EF5 Migrations - Duplicate/Re-defined variable bug when dropping constraints | Issue with usage of SQL GO command

喜你入骨 提交于 2019-11-30 17:17:42

I put a Sql("--<GO>"); at the end of each migration. This runs OK as an applied migration and when I script the SQL I just do a find and replace on "--<GO>" to "GO". A bit manual but works for me. You could put Sql("--<GO>"); around your create trigger statements.

As per msdn

"GO is not a Transact-SQL statement; it is a command recognized by the sqlcmd and osql utilities and SQL Server Management Studio Code editor."

Since you are not using any of the above tools but SqlCommand class to execute your Sql statement Sql Server (and not EF - see the stack trace where the exception originated) is choking on it

Stanley.Goldman

After I experienced the problem first hand..

We decided to create smaller migrations. If the change was big enough that it required a GO command, then the developer was attempting to change too much in a migration. Unfortunately, the only way to control what goes into a migration is to comment out the changes.

I also pondered why I wanted the script so badly. Its not like I didn't trust EF to perform the migration correctly, (provided I tested it first). Ideally I would never and (thankfully) have yet to have a reason to modify it. I've only looked at it a few times when I started using EF Code First.

I don't like this answer, but I don't think it serves a purpose other than debugging a migration for Entity Framework Code First.

Just delete all the repetitions of this line:

DECLARE @var0 nvarchar(128)

Only the first declaration is sufficient. Your script will work smoothly! :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!