生成丢失的迁移,以便我可以更新旧的数据库结构 [英] Generate missing migrations so I can update an old database structure

查看:63
本文介绍了生成丢失的迁移,以便我可以更新旧的数据库结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我首先在迁移中使用EF代码。我需要更新旧数据库
,但是我丢失了一些迁移代码。
是否可以生成丢失的迁移?

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 )

步骤2:删除__MigrationHistory

Step 2: Delete __MigrationHistory

步骤3:创建一个临时项目。
使用实体数据模型向导创建代码优先模型。

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

步骤4:在新项目中启用迁移(使用Enable-Migrations)。程序包管理器控制台。

创建一个初始迁移(使用add-migration one)。注释掉所创建迁移的Up和Down方法。

运行update-database。

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.

步骤5:替换Migrations文件夹中的所有文件原始项目以及临时项目中的文件。

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.

步骤6在包管理器的原始项目中,运行Add-Migration两个
,然后运行update-database

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

这篇关于生成丢失的迁移,以便我可以更新旧的数据库结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆