EF Add-Migration指示“无待决的显式迁移”。但Update-Database抱怨“ ..有待处理的更改”。 [英] EF Add-Migration indicates "No pending explicit migrations" but Update-Database complains "..there are pending changes"

查看:251
本文介绍了EF Add-Migration指示“无待决的显式迁移”。但Update-Database抱怨“ ..有待处理的更改”。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Entity Framework代码首次迁移时,我经常遇到以下情况。我添加了一些迁移,并成功地用它们更新了数据库。稍后,当我希望添加新的迁移时,Add-Migration命令会抱怨其由于以下显式迁移正在等待中而无法生成显式迁移...。也就是说,似乎忘记了它以前已经应用了这些迁移,因此现在不应将其视为待处理。如果我尝试解决此问题,则Update-Database指示由于存在[新]待更改,因此无法更新数据库以匹配当前模型...。我不明白为什么EF迁移会不同步,因为我只对模型进行了更改。

I frequently encounter the following situation with Entity Framework code first migrations. I add some migrations and update the database with them successfully. When later I wish to add a new migration, the Add-Migration command complains that its "Unable to generate an explicit migration because the following explicit migrations are pending...". I.e., it seems to forget that its already applied those migrations previously and therefore they shouldn't be now considered as pending. If I try to workaround this issue, Update-Database indicates "Unable to update database to match the current model because there are [new] pending changes...". I don't understand why EF migrations getting out of sync since I'm only making changes to the model.

推荐答案

对我来说问题是我们已将迁移的名称空间重命名为2014123456_Initial.cs。

但是VS尚未在其关联的2014123456_Initial.Designer.cs中重新生成名称空间。

For me the issue was that we had renamed the namespace of the migration 2014123456_Initial.cs.
But VS had not regenerated the namespace in its associated 2014123456_Initial.Designer.cs.

将Designer.cs更改为使用相同的名称空间后,它们又重新开始工作。

Once the Designer.cs was changed to use the same namespace, it all started working again.

这篇关于EF Add-Migration指示“无待决的显式迁移”。但Update-Database抱怨“ ..有待处理的更改”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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