I'm calling the HasData method (see below) for an entity that has an Id (Identity) column, but no data is inserted into the table the first time the Migration runs.
When the TestObject model was not using an Id (Identity) column for the Primary Key, data was inserted as expected the first time the migration was run.
Is EF Core able to insert data for Identity columns?
modelBuilder.Entity<TestObject>().HasData(
new TestObject
{
Id = 1,
TestValue = "Test 1"
}
HasData
requires providing PK values, so it should (is supposed to) work with auto-generated (identity and similar) keys. What EF Core version are you using? And which database provider? – BacksightUpdate-Database -Verbose
on clean new database and post the output? Hope you haven't used code similar tocontext.Database.EnsureCreated();
because it breaks migration system. – BacksightInsertData
with the data you specified. – Limburger