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
标签:
ef-migrations