Skip to content

Commit

Permalink
Add explanatory comment for JSON hack (#2967)
Browse files Browse the repository at this point in the history
  • Loading branch information
roji committed Nov 20, 2023
1 parent 4d34642 commit dd3c6a2
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/EFCore.PG/Migrations/NpgsqlMigrationsSqlGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1608,6 +1608,11 @@ protected override void DefaultValue(
string? columnType,
MigrationCommandListBuilder builder)
{
// This is a hacky workaround for https://github.com/dotnet/efcore/issues/32353 - the EF MigrationsModelDiffer generates an empty
// string as the default value for JSON columns, but that's not valid as a JSON document and rejected by PG's jsonb type. So we
// replace the empty string with an empty JSON document {}.
// Note that even after the EF-side issue is fixed, removing this hack is a breaking change as migrations have already been
// scaffolded with an empty string.
if (columnType is "jsonb" or "json" && defaultValue is "")
{
defaultValue = "{}";
Expand Down

0 comments on commit dd3c6a2

Please sign in to comment.