-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Idempotent migration script not working on EFCore7.0 for AlterColumn when nullable changed from true to false #29530
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Milestone
Comments
/cc @bricelam |
roji
added a commit
to roji/efcore
that referenced
this issue
Nov 19, 2022
roji
added a commit
that referenced
this issue
Nov 21, 2022
roji
added a commit
to roji/efcore
that referenced
this issue
Dec 6, 2022
…otnet#29619) Fixes dotnet#29530 (cherry picked from commit 6b3b852)
roji
added a commit
to roji/efcore
that referenced
this issue
Dec 7, 2022
…otnet#29619) Fixes dotnet#29530 (cherry picked from commit 6b3b852)
roji
added a commit
to roji/efcore
that referenced
this issue
Nov 17, 2023
…otnet#29619) Fixes dotnet#29530 (cherry picked from commit 6b3b852)
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
After upgrading to .NET7 a Azure DevOps pipeline failed. Investigating I found that the idempotent migration script we generate to be applied to the target Azure SQL Database is failing to be applied, with the error
##[error]Invalid column name 'CurrentSiteInvestigationDelayStatus_InvestigationDelayInSeconds'.
Include your code
Generating the idempotent migration script locally using .NET6 and then .NET7 reveals a difference in the generated SQL migration code.
I have a migration definition defined as
Essentially the property is no longer nullable, and has a default value defined.
in .NET6 this migration was generated as
in .NET7 this is generated as
The difference is in the .NET7 migration there is a
I understand why this has been added, as previously I have created SQL updates like this to ensure any existing rows have the default applied where the current value is NULL.
However, in this situation the column name has since been changed in a later migration. Therefore when running the SQL script we encounter the error
The UPDATE statement should be wrapped in an EXEC(''); as recommended in the official docs here Arbitrary changes via raw SQL
Include provider and version information
EF Core version:
Database provider: (e.g. Microsoft.EntityFrameworkCore.SqlServer)
Target framework: (e.g. .NET 7.0)
Operating system: WIndows 11
IDE: (e.g. Visual Studio 2022 17.4)
The text was updated successfully, but these errors were encountered: