为什么代码首次迁移EF要求创建新迁移,何时已存在? [英] Why is code first migrations EF asking to create new migration, when already exists?

查看:111
本文介绍了为什么代码首次迁移EF要求创建新迁移,何时已存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我加载了一个旧项目来修复bug。



项目尝试运行初始化程序,但是这样做抱怨存在未决的数据库更改,或模型不正确等。



所以我的问题是:



1)为什么会这样当网站上线并且已经正常工作时,请求另外一个迁移被添加到运行成功吗?



2)为什么脚手架已经存在的迁移? br />


我尝试过:



在控制台中添加迁移,它支持迁移。然而,新的脚手架迁移与预先存在的Intial_Create迁移完全相同(这是1和唯一的迁移)。

So i loaded up an old project to fix a bug.

The project tries to run the initialiser, but upon doing so complains that there are pending database changes, or the model is incorrect etc.

So my questions are:

1) Why is it requesting another migration to be addded to run succesffuly, when the site has gone live and already works fine?

2) Why is it scaffolding a migration that already exists?

What I have tried:

Add-Migration in the console, and it scaffolds the migration. However the newly scaffolded migration is exactly the same as the pre-existing "Intial_Create" migration (this is the 1 and only migration).

推荐答案

Plz首先备份你的项目。然后按照以下步骤操作。



转到项目(如果是多个项目)哪个有EF上下文类。删除[Migration]文件夹。



然后进入Nuget Package Manager控制台。



并在下拉列表中选择项目(如果有多个项目)。然后运行以下命令以使EF正常运行。



Plz first take backup of your project. Then follow these steps.

Go to the project (if multiple projects) Which have EF context class. Delete the [Migration] folder.

Then go in Nuget Package Manager Console.

And in dropdown select the project (if multiple projects). And then run following commands to get things OK for EF.

Enable-Migrations





这将再次生成迁移文件夹



然后在Nuget Con再次点火命令......





This will generate again the migration folder

Then again fire command in Nuget Con...

Add-Migration 'with any message'





这将推动事物如果有任何待定的更改那么



然后再次点击最后一个命令





This will push things if any pending changes there

then again fire last command

Update-Database





现在你的Ef又好了回来



Now ur Ef is OK back again


这篇关于为什么代码首次迁移EF要求创建新迁移,何时已存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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