Skip to content

Commit

Permalink
Fix adding a new non-nullable JSON column (#2967)
Browse files Browse the repository at this point in the history
Fixes #2965
  • Loading branch information
roji authored Nov 20, 2023
1 parent 4464d47 commit 4d34642
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/EFCore.PG/Migrations/NpgsqlMigrationsSqlGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1601,6 +1601,21 @@ protected override void ColumnDefinition(
}
}

/// <inheritdoc />
protected override void DefaultValue(
object? defaultValue,
string? defaultValueSql,
string? columnType,
MigrationCommandListBuilder builder)
{
if (columnType is "jsonb" or "json" && defaultValue is "")
{
defaultValue = "{}";
}

base.DefaultValue(defaultValue, defaultValueSql, columnType, builder);
}

/// <summary>
/// Checks for a <see cref="NpgsqlAnnotationNames.TsVectorConfig" /> annotation on the given column, and if found, assigns
/// the appropriate SQL to <see cref="ColumnOperation.ComputedColumnSql" />.
Expand Down

0 comments on commit 4d34642

Please sign in to comment.