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
.
For this reason, it always failed on EF model binding with error message as below;
Column names in each table must be unique. Column name 'SomeProperty' in table 'dbo.CommandModels' is specified more than once.
Weired thing is that, web.config.dev
is applied to development database without any trouble, but web.config.production
makes such problem. Both config files have same hierarchy except database connectionstring and Publish
wizard have checked Update Database
identically.
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. This remedy is given from 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')
Why is this happened?
My Bad.
I checked at LogConnectionString
for [v] update database
, not DefaultConnection
in the Publish > Settings
dialog. It was invisible by scroll range.
If someone has same issue, double-check that you ticked to right connectionstring.