Entity framework migration and seeding specific update
Asked Answered
J

2

24

does anyone know how you can seed a specific update using EF 5 migrations? I have existing database, alredy has lookups populated, and am developing some Audit functionality. I have created an AuditType entity and Audit. When I call update-database, I don't want all my seed data from when I first created the database to be re-added. Do I simply have to manuall delete the existing seed data out or can I do something like name a Configuration.cs with the datetime similar to what gets created when I call add-migration?

Thanks

Junina answered 27/8, 2013 at 18:49 Comment(0)
S
48

You can run a specific migration by specifying the name of the migration. For example, If you have a migration called MyTuesdayMigration.cs, In the package manager console, you would run this command:

update-database -TargetMigration MyTuesdayMigration
Search answered 5/9, 2013 at 8:17 Comment(3)
Hi Greg, So would you place your "seeding" statements that relate to that particular update/upgrade in the "Up" method in your "MyTuedayMigration" then rather than using the "seed" method in the Configuration.cs which, if I have set everything up correctly, resides at Migrations folder level and not in Migrations->MyTuesdayMigration??Junina
Yes, place it in the up method. In your case you don't want your seed method to populate the data (if my understanding is correct).There is nothing special about the up method. You can run it whenever you want.Search
ef core : update-database -migration test32Sticky
S
1

You may need to delete data so you should use -fore update-database -TargetMigration MigrationName -force

Sherleysherline answered 2/7, 2016 at 20:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.