-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EF Core 8.0.3 produces incorrect idempotent migration script #33337
Comments
I'm having this exact issue. +1 please fix. |
This issue remains in the fresh version 8.0.4. |
I might have found was it causing this. If I have this migration class: public partial class AddsCustomerGroupTables : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql(@"
SELECT GetDate()
GO
SELECT GetDate()
GO
SELECT GetDate()
GO
");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
}
} Then the incorrect SQL is generated. My current guess the that the last |
Yep, It's the last GO that causes this. I just fixed it in my project by updating about a dozen sql scripts that were triggering this. |
The problem is not the GO statement, it are the empty lines after the GO statement. This issue started by this commit: 9b8b38f#diff-c80a80f96194920fd36fd4daaa22d80408aaa7f083128172c4c05331f0b92de0 Before that commit, empty lines were ignored so no new batch was created after the GO statement. Now after the GO statement a new batch is started but only contains empty lines which is the error. Proposed solution: check wether the batch is empty before adding it to the builder (MigrationCommandListBuilder) |
Just mentioning the actual PR that caused the break: #32788 Unfortunately, setting the app context switch (which is present in the backport PR, not present in the PR to main) does not resolve this specific issue. |
The issue is still present in 8.0.8 version |
After I updated a library from this:
To this:
I get incorrect SQL when I'm build migration script. I run this command:
Then I get a large SQL script. Almost everything is correct. But this correct snippet:
Is changed to:
Somehow, a
BEGIN
followed directly by andEND
is not valid SQL I guess.I have checked this migration, and migrations before that, and I do not se anything special.
Unfortunate, I haven’t been able to reproduce this in a new library and I cannot share the code in public. But I do not mind sharing the code with someone in the team if needed. In my build pipeline I produced 6 migrations script, and only one of these has this problem.
Include provider and version information
EF Core version: 8.0.3 / 8.0.4
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 8.0
The text was updated successfully, but these errors were encountered: