Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"argument 'sql' cannot be null" when including "Go" in EF DbMigration

When adding the SQL server GO command to a DbMigration.Sql("GO ...") call causing the Update-Database entity framework method to throw the exception "argument 'sql' cannot be null".

Remove the GO and the migration fails because the next SQL statement is creating a trigger, which must be on its own.

like image 656
Jono Avatar asked Apr 14 '16 21:04

Jono


1 Answers

I found absolutely no info on this issue, so thought SO might benefit.

From reading around, I found that in SQL Server GO must be followed by a newline, so I think the root cause to this issue has to do with that and how EF parses the SQL before sending to the DB.

The way I solved the issue was discovering an optional parameter to the DbMigration.Sql(sql, suppressTransaction=false) method.

suppressTransaction forces the sql query to be separate to the rest of the migration (usually this is all called as one transaction). Hence removing my need to use GO at all.

like image 121
Jono Avatar answered Oct 04 '22 19:10

Jono