Skip to content

Commit

Permalink
Quirk for #24272
Browse files Browse the repository at this point in the history
  • Loading branch information
roji committed Mar 1, 2021
1 parent 2565afa commit e234d86
Showing 1 changed file with 8 additions and 1 deletion.
Expand Up @@ -38,6 +38,9 @@ public class SqlServerMigrationsSqlGenerator : MigrationsSqlGenerator
private IReadOnlyList<MigrationOperation> _operations;
private int _variableCounter;

private static readonly bool _useOldAlterColumnDefaultValueLogic =
AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue24272", out var enabled) && enabled;

/// <summary>
/// Creates a new <see cref="SqlServerMigrationsSqlGenerator" /> instance.
/// </summary>
Expand Down Expand Up @@ -391,7 +394,11 @@ protected override void Generate(AddCheckConstraintOperation operation, IModel m
builder.AppendLine(Dependencies.SqlGenerationHelper.StatementTerminator);
}

if (!Equals(operation.DefaultValue, oldDefaultValue) || operation.DefaultValueSql != oldDefaultValueSql)
var addDefaultValue = _useOldAlterColumnDefaultValueLogic
? operation.DefaultValue != null || operation.DefaultValueSql != null
: !Equals(operation.DefaultValue, oldDefaultValue) || operation.DefaultValueSql != oldDefaultValueSql;

if (addDefaultValue)
{
builder
.Append("ALTER TABLE ")
Expand Down

0 comments on commit e234d86

Please sign in to comment.