Generate missing migrations so I can update an old database structure

寵の児 提交于 2019-12-13 07:34:01

问题


I am using EF Code first with Migrations. I need to update an old database however I have lost some of the migration code. Is there a way to generate the missing migrations?


回答1:


Step 1: Back up ( obviously )

Step 2: Delete __MigrationHistory

Step 3: Create a temporary project. Use the Entity Data Model Wizard to create the Code-First Model.

Step 4: Enable migrations in the new project ( using Enable-Migrations) at the Package Manager Console.
Create an initial migration ( using add-migration one). Comment out the Up and Down methods of the created migration.
Run update-database.

Step 5: Replace all the files in the Migrations folder of the original project with the files in the temporary project. Editing DbContext and namespace names as required.

Step 6 In the original project in package manager run Add-Migration two then run update-database



来源:https://stackoverflow.com/questions/42568212/generate-missing-migrations-so-i-can-update-an-old-database-structure

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!