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

CheGuevarasBeret
  • 1,364
  • 2
  • 14
  • 33

2 Answers2

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
Jeff
  • 810
  • 8
  • 18
Greg
  • 2,654
  • 3
  • 36
  • 59
  • 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?? – CheGuevarasBeret Sep 07 '13 at 14:21
  • 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. – Greg Sep 07 '13 at 15:39
  • ef core : update-database -migration test32 – Kugan Kumar Dec 04 '20 at 03:05
1

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

foluis
  • 988
  • 2
  • 10
  • 23