I thought that instead of trying to make as little change as possible in the migration, i should simply drop all foreign keys and tables and re-create them with the proper type of Id.
This way i can avoid the errors that are thrown by EF due to changing string to int.
Instead of doing something likes this in the migration:
migrationBuilder
.AlterColumn<int>(
name: "Id",
table: "AspNetUsers",
oldClrType: typeof(string));
I do something like this:
migrationBuilder.DropForeignKey(name: "FK_AspNetRoleClaims_AspNetRoles_RoleId", table: "AspNetRoleClaims");
// Drop the other FKs as well.
migrationBuilder.DropTable(name: "AspNetRoles");
// Drop the other tables as well.
migrationBuilder.CreateTable(
name: "AspNetUsers",
columns: table => new
{
Id = table.Column<int>(nullable: false),
UserName = table.Column<string>(maxLength: 256, nullable: true),
NormalizedUserName = table.Column<string>(maxLength: 256, nullable: true),
Email = table.Column<string>(maxLength: 256, nullable: true),
NormalizedEmail = table.Column<string>(maxLength: 256, nullable: true),
EmailConfirmed = table.Column<bool>(nullable: false),
PasswordHash = table.Column<string>(nullable: true),
SecurityStamp = table.Column<string>(nullable: true),
ConcurrencyStamp = table.Column<string>(nullable: true),
PhoneNumber = table.Column<string>(nullable: true),
PhoneNumberConfirmed = table.Column<bool>(nullable: false),
TwoFactorEnabled = table.Column<bool>(nullable: false),
LockoutEnd = table.Column<DateTimeOffset>(nullable: true),
LockoutEnabled = table.Column<bool>(nullable: false),
AccessFailedCount = table.Column<int>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetUsers", x => x.Id);
});
// Create the other tables as well.
Although i'm not sure if there's a more elegant way to replace every UserId, RoleId and Id of AspNetUser, AspNetRole table to int.