Generate missing migrations so I can update an old

2019-09-12 01:43发布

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条回答
ら.Afraid
2楼-- · 2019-09-12 02:14

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

查看更多
登录 后发表回答