简体   繁体   中英

The Update-Database Add-Migration loop

I thought I figured it out when I disabled AutomaticMigrations.

I Update-Database then Add new column name to DAL class.

Then execute Add-Migration

But I am caught in a loop of nonsense.

I execute Update-Database and am treated to ... Applying explicit migrations: [a list of the current migrations].

then this line for each migration. Applying explicit migration: [id]

Then it warning me that the model is NOT up to date. So I execute Add-Migration and get the error... Unable to generate an explicit migration because the following explicit migrations are pending: [the same list I just saw applied]

WTF?

I resolved this through the following steps.

  1. Delete the dataabase file your DAL project is updating.
  2. Remove the offending migration. // Comment out the offending column or table.
  3. Execute Update-Database.
  4. Uncomment changes.
  5. Add-Migration
  6. Update-Database
  7. Runtime check.
  8. Check-in

Good luck if you run into this problem.

I further ran into problems when I added code that explicitly called the initializer to speed up startup time. Then whenever I did an update-database...it would use my context class, try to do the initializer and fail.

Code-First is a good step in the right direction but it has all these be careful scenarios.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM