Idempotent migration script not working on EFCore7.0 for AlterColumn when nullable changed from true to false #29530
Labels
area-migrations
area-sqlserver
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
customer-reported
Servicing-approved
type-bug
Milestone
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: