简体   繁体   中英

C# Entity Framework Database Migrations in Class Library

I have a solution with an MVC 4 project and a class library. Both the MVC 4 project and the class library have database migrations enabled on them. I can run "Update-Database" for each project and apply both migrations to the database but when I try to add an addition migration to either project, the migration includes code to remove the tables from the other project's migrations. Any help on this would be appreciated.

Note: This is not a duplicate. This question is about migrations. My problem is that each set of migrations takes over the entire database.

Code first right?

i'm not sure if this will answer your question but you can try either of the following

  • CreateDatabaseIfNotExists - this will only recreate the database if it does not exists
  • DropCreateDatabaseAlways - this will always recreate the database, this will delete the current database including the data then recreate the database schema
  • DropCreateDatabaseIfModelChanges - this will recreate the database if you change your model classes and will loose all the data.

hope that helps

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