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

前端 未结 4 1564
灰色年华
灰色年华 2021-01-04 01:37

Background:

We have a project that uses ef-migrations containing multiple (read ~60) migrations created over a long period of development. Naturally, some of these

相关标签:
4条回答
  • 2021-01-04 01:59

    Just delete all the repetitions of this line:

    DECLARE @var0 nvarchar(128)
    

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

    0 讨论(0)
  • 2021-01-04 02:13

    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.

    0 讨论(0)
  • 2021-01-04 02:17

    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.

    0 讨论(0)
  • 2021-01-04 02:18

    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

    0 讨论(0)
提交回复
热议问题