Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EF Core Code First Oracle - Cannot set nullable an existing colum

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:

enter image description here

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);
like image 835
Matthieu Charbonnier Avatar asked Jan 02 '26 02:01

Matthieu Charbonnier


1 Answers

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");
    }
like image 151
Matthieu Charbonnier Avatar answered Jan 04 '26 13:01

Matthieu Charbonnier



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!