编辑: 似乎是第二次运行时,迁移中的自定义SQL查询出错了,因为第二次运行时该表不再存在。因此(我认为)SQL无法解析,因此失败。现在的问题是:如何编写自定义SQL,以便它在第二次运行时能够成功解析
我正在尝试发布我的Asp.Net Core Web应用程序。当我尝试发布时,出现以下错误
Error details:An error occurred during execution of the database script. The error occurred between the following lines of the script: "1143" and "1150". The verbose log might have more information about the error. The command started with the following:
"IF NOT EXISTS(SELECT * FROM [__EFMigrationsHisto"
Invalid column name 'x'.
Invalid column name 'y'. http://go.microsoft.com/fwlink/?LinkId=178587
Learn more at: http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_SQL_EXECUTION_FAILURE.) Web 0
现在,x和y列已添加到我的最新迁移中,但是,该迁移已应用于数据库(〜635):
Visual Studio:
MSSQL:
EF想要应用此迁移的原因可能是什么?我可以详细运行Web部署以获得更多信息吗? “脚本”是什么意思?
预先感谢
编辑:没有其他人将迁移应用到该数据库,没有任何挂起的更改(add-migration提供空迁移),此连接之前已经起作用,并且实际上没有任何更改。
Edit2:以下代码似乎有问题。我运行了if语句,它返回了一行,这意味着主体不应该执行,但是它仍然在此行崩溃
IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20190521095635_ContractHistory')
BEGIN
select * from AspNetUsers DECLARE @UserId nvarchar(450) DECLARE MY_CURSOR CURSOR LOCAL STATIC READ_ONLY FORWARD_ONLY FOR SELECT DISTINCT Id FROM AspNetUsers OPEN MY_CURSOR FETCH NEXT FROM MY_CURSOR INTO @UserId WHILE @@FETCH_STATUS = 0 BEGIN insert into Contracts(UserId, ContractHours, StartDate) select Id, ContractHours, ContractDatum from AspNetUsers where Id = @UserId PRINT @UserId FETCH NEXT FROM MY_CURSOR INTO @UserId END CLOSE MY_CURSOR DEALLOCATE MY_CURSOR
END;