This is short: I have mistakenly set a property string
when it should've been int
. There are no constraints as this int
may be optional. Even though I could make the int nullable, I rather have it a default value of zero.
Then when I try to run migrations:
Cannot insert the value NULL into column 'Edad', table 'EduPlaTools.dbo.Profesor'; column does not allow nulls. UPDATE fails. The statement has been terminated.
Which makes sense. What it's doing is updating the fields, and since many fields had "NULL", it's getting inserted. Is there a way to map those NULLs into zeroes automatically? Or do I need to do an SQL Statement?
Here's the migrationBuilder code:
migrationBuilder.AlterColumn<int>(
name: "Edad",
table: "Profesor",
nullable: false,
oldClrType: typeof(string),
oldNullable: true);
defaultValue: 0,
?