Reputation: 9490
I have an initial DB migration. Now I need to create the first incremental migration. When I create the first incremental migration with
add-migration Incremental1
it contains not only the table changes but all data changes as well. For example for rows that were added in between into the table it contains DeleteData
commands:
migrationBuilder.DeleteData(
table: "SystemResources",
keyColumn: "Id",
keyValue: 1);
Is there some setting for generating only table changes (added/removed columns) and ignoring all data changes (inserted data rows)?
Upvotes: 1
Views: 2273
Reputation: 9490
The solution is to:
modelBuilder.Entity<T>().HasData
statements,add-migration
,DeleteData
/ InsertData
commands from the incremental migration,update-database
.After this, the seed data is no longer part of the model snapshopt (<Database>ModelSnapshot.cs
file) and is therefore no longer tracked by migrations.
This also means the next incremental migration will not contain any DeleteData
/ InsertData
statements.
Upvotes: 3