EF - 从自动移动到手动迁移 [英] EF - Moving from AutomaticMigrations to Manual Migrations

查看:157
本文介绍了EF - 从自动移动到手动迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

测试各种场景的漫长的一天结束,我不必重新创建一个生产数据库...

End of long day of testing various scenarios where I don't have to recreate a production database...

我们从EF开始,没有在开发过程中明智地从自动迁移迁移到命名迁移。现在我试图倒退时钟,并创建一个与生产数据库对齐的初始迁移。

We started off with EF, and didn't get wise enough during development to move from automatic migrations to named migrations. Now I'm trying to rewind the clock, and create an initial migration that aligns with the production database.


  1. 这是否可以对齐模型已经在迁移表中有自动迁移?

  2. 我应该创建一个空迁移来开始命名迁移吗?我唯一的问题是如何在新的开发人员加入时创建数据库...我可以简单地恢复数据库,然后应用迁移,但是这样就会造成一个美丽的EF移植故事!

  3. 删除生产数据库,创建和编写脚本以重新导入数据(听起来很奇怪)。

另一个皱纹 - DB是使用EF5创建的,我们现在正在使用EF6开发。

Another wrinkle - the DB was created with EF5, and we are now developing with EF6.

提前感谢您的帮助。

推荐答案

应该可以:


  1. 删除__MigrationHistory表

  2. 删除项目中的任何迁移

  3. 在迁移配置类中禁用自动迁移

  4. 添加迁移InitialCreate

  5. 更新数据库-Script

  6. 执行创建__MigrationHistory表的脚本部分,并在其中插入一行

  7. 重复步骤1& 6对于任何其他现有数据库

  1. Delete the __MigrationHistory table
  2. Delete any migrations in your project
  3. Disable automatic migrations in your migrations configuration class
  4. Add-Migration InitialCreate
  5. Update-Database -Script
  6. Execute the portion of the script that creates the __MigrationHistory table and inserts a row into it
  7. Repeat steps 1 & 6 for any other existing databases

我还强烈建议阅读团队环境中的代码首次迁移

这篇关于EF - 从自动移动到手动迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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