简体   繁体   English

实体框架不会创建新的迁移:数据库名称无效

[英]Entity Framework does not create a new migration: database name is invalid

We are using Entity Framework migrations in a project. 我们正在项目中使用Entity Framework迁移。 So far we have added several migrations with no problem but it stopped working. 到目前为止,我们已经添加了几个迁移,没有问题,但是它停止了工作。 Now whenever we try to add a migration EF shows an error with the following message: 现在,每当我们尝试添加迁移时,EF都会显示以下错误消息:

The database name 'my-table-name' is invalid. 数据库名称“ my-table-name”无效。 Database names must be of the form [schema_name.]object_name. 数据库名称的格式必须为[schema_name。] object_name。

Furthermore if we execute the update-database command, EF tells us that the model does not match the database. 此外,如果执行update-database命令,EF会告诉我们该模型与数据库不匹配。 But the model has not been changed (we want to create an "empty" migration). 但是模型没有改变(我们想创建一个“空”迁移)。

We have tried to go back to previous migrations, start from scratch but we always get the same result. 我们已经尝试从头开始回到以前的迁移,但是我们总是得到相同的结果。 Oddly enough sometimes the invalid table varies. 奇怪的是,有时无效表会有所不同。 We don't think is related to any pluralization issues on the context configuration. 我们认为与上下文配置中的任何多元化问题无关。

Any help will be greatly appreciated. 任何帮助将不胜感激。

  • Entity-Framework version: 6.1.3-40302 实体框架版本:6.1.3-40302
  • Database: SQL Server 11.0.5058.0 数据库:SQL Server 11.0.5058.0

Finally the solution was quite straight forward, just run the Add-Migration command along with the IgnoreChanges parameter. 最后,解决方案非常简单,只需运行Add-Migration命令以及IgnoreChanges参数即可。

This did not yeld any error and created a blank migration. 这没有产生任何错误并创建了空白迁移。 Then, we updated the database without adding anything to the blank migration, deleted the files attached to it and we were able to create standard migrations again. 然后,我们更新了数据库,但未向空白迁移中添加任何内容,删除了数据库中附加的文件,从而能够再次创建标准迁移。

Why EF could not add new migrations before and the origin of the error message is still a mistery to us. 为什么EF以前无法添加新迁移,并且错误消息的出处仍然令我们感到困惑。

Thank you everyone for your help! 谢谢你们每一个人的帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM