I set an existing property decimal to decimal?:
public decimal? TotalAmountTTC { get; set; }
Then I created a migration with add-migration, it generated me this :
migrationBuilder.AlterColumn<decimal>(
name: "c0003_total_amount_ttc",
table: "t0003_transfer_request",
type: "decimal(13,4)",
nullable: true,
oldClrType: typeof(decimal),
oldType: "decimal(13,4)");
But after i execute update-database, the column is still not nullable:

When i run script-migration to check the SQL generated, we can see it clearly doesn't care about the fact my property is now nullable:
ALTER TABLE "t0003_transfer_request" MODIFY "c0003_total_amount_ttc" decimal(13,4)
/
Am I doing something wrong? Is this a bug?
I've tried to set the IsRequired(false) in the mapping, but same result.
builder.Property(tr => tr.TotalAmountTTC).HasColumnName("c0003_total_amount_ttc").IsRequired(false);
Ok, it looks like a hack to me, but I've found a way to make NULLABLE a column which already exists as NOT NULL :
You need to include the NULL in the datatype (in my case : decimal(13,4) NULL) :
public void Configure(EntityTypeBuilder<TransferRequest> builder)
{
builder.Property(tr => tr.TotalAmountTTC).HasColumnType("decimal(13,4) NULL");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With