Open
Description
Entity Framework 6.2.0
Npgsql 4.0.2
EntityFramework6.Npgsql 3.2.0
Adding integer field/column to table that currently have records in it causes error on automatic migrations:
'23502: column "xxxx" contains null values'
The executed SQL command is:
ALTER TABLE "xxx"."yyy" ADD "zzz" int4 NOT NULL
The same migration works in SQL Server and MySQL with no issues, setting the field in existing rows with type default value.
I think that a default value should be set for non-nullable columns when migrating, which must be the default value for type, in this case 0
.
The SQL statement should be:
ALTER TABLE "xxx"."yyy" ADD "zzz" int4 NOT NULL DEFAULT 0
P.S: Annotating entity field with [DefaultValue(0)]
does not change anything.
P.P.S:
The solution - in NpgsqlMigrationSqlGenerator
, line 577, the following should be added:
else if (!(column.IsNullable ?? false) && column.ClrDefaultValue != null)
{
sql.Append(" DEFAULT ");
AppendValue(column.ClrDefaultValue, sql);
}
Metadata
Metadata
Assignees
Labels
No labels