I’m seeding the User identity table using EF core configurations, this is my method.
public void Configure(EntityTypeBuilder<IdentityUser> builder)
{
var hasher = new PasswordHasher<IdentityUser>();
var adminUser = new IdentityUser
{
Id = Id,
UserName = AdminUserName,
NormalizedUserName = AdminUserName,
Email = AdminUserName,
NormalizedEmail = AdminUserName,
EmailConfirmed = true,
ConcurrencyStamp = ConcurrencyStamp,
SecurityStamp = SecurityStamp
};
adminUser.PasswordHash = hasher.HashPassword(adminUser, Password);
builder.HasKey(u => u.Id);
builder.Property(u => u.Id).ValueGeneratedNever();
builder.Property(u => u.ConcurrencyStamp).ValueGeneratedNever();
builder.Property(u => u.PasswordHash).ValueGeneratedNever();
builder.Property(u => u.SecurityStamp).ValueGeneratedNever();
builder.HasData(adminUser);
}
It works great when creating the first migration, applying all the fields i listed in the code.
The issue arises when i create a second migration (even without changing anything), it always create a migration trying to change the password hash, even if i specified to never generate the value.
public partial class UserAndRoleSeed3 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.UpdateData(
schema: "Users",
table: "AspNetUsers",
keyColumn: "Id",
keyValue: "0fbad743-9b2c-4eac-aa17-957880a5465d",
column: "PasswordHash",
value: "AQAAAAIAAYagAAAAELfdYk76pRqQjoKQM9cOrCEplDXzB2mFhQdaCByEIBU4ng6fb9FtK7rY6sCLKwhS8A==");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.UpdateData(
schema: "Users",
table: "AspNetUsers",
keyColumn: "Id",
keyValue: "0fbad743-9b2c-4eac-aa17-957880a5465d",
column: "PasswordHash",
value: "AQAAAAIAAYagAAAAELG0nqfYzxLsa3gKh8PlUIx23oUZOe4RJjrk1DRPSdYvdkDqoQsTVhCApmGOx0awVw==");
}
}
How can i avoid this issue with migrations? Thanks
Sgri is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.