简体   繁体   English

EntityFramework不添加__MigrationHistory记录

[英]EntityFramework does not add __MigrationHistory record

While publishing [ASP.NET WebApi + EF6 + SlowCheetah + Azure SQL] webapp from VisualStudio 2015, production database schemas are updated without adding new migration record to __MigrationHistory . 从Visual Studio 2015发布[ASP.NET WebApi + EF6 + SlowCheetah + Azure SQL] Webapp时,将更新生产数据库架构,而无需向__MigrationHistory添加新的迁移记录。

For this reason, it always failed on EF model binding with error message as below; 因此,在EF模型绑定时总是失败,并显示以下错误消息;

Column names in each table must be unique. 每个表中的列名必须唯一。 Column name 'SomeProperty' in table 'dbo.CommandModels' is specified more than once. 表“ dbo.CommandModels”中的列名“ SomeProperty”被多次指定。

Weired thing is that, web.config.dev is applied to development database without any trouble, but web.config.production makes such problem. 奇怪的是,将web.config.dev毫无问题地应用于开发数据库,​​但是web.config.production出现了此类问题。 Both config files have same hierarchy except database connectionstring and Publish wizard have checked Update Database identically. 这两个配置文件具有相同的层次结构,只是数据库连接PublishPublish向导已检查Update Database相同。

To fix this, I always run update-database -f -script , copy the last line (below quoted script), and execute it in SSMS or VS after publishing. 为了解决这个问题,我总是运行update-database -f -script ,复制最后一行(引用脚本下面),并在发布后在SSMS或VS中执行它。 This remedy is given from https://stackoverflow.com/a/13957069/361100 . 该补救措施是从https://stackoverflow.com/a/13957069/361100提供的

INSERT [dbo].[__MigrationHistory]([MigrationId], [ContextKey], [Model], [ProductVersion]) VALUES (N'201610070644166_AddAppId', N'Recognition.WebApi.Migrations.Configuration', 0x1F8B0800000000000400ED5CDD6C00E3377481D67897B9418EFA035E217753DC80C62C8C4C0000 , N'6.1.3-40302') 插入[dbo]。[__ MigrationHistory]([MigrationId],[ContextKey],[Model],[ProductVersion])值(N'201610070644166_AddAppId',N'Recognition.WebApi.Migrations.Configuration',0x1F8B0800000000000400ED5CDD6C00E931678167 -40302')

Why is this happened? 为什么会这样呢?

My Bad. 我的错。

I checked at LogConnectionString for [v] update database , not DefaultConnection in the Publish > Settings dialog. 我在LogConnectionString检查了[v] update database ,而不是“ Publish > Settings对话框中的DefaultConnection It was invisible by scroll range. 通过滚动范围看不到它。

If someone has same issue, double-check that you ticked to right connectionstring. 如果有人遇到同样的问题,请仔细检查您是否勾选了正确的连接字符串。

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

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