Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EntityFramework migration not removing 'IsRequired' from column

I have an int column which is currently mandatory

builder.Property(p => p.PropertyArea).IsRequired();

... but needs to be non-mandatory

builder.Property(p => p.PropertyArea)

But after applying Add-Migration migrationName, update-database etc there is no change to the column in sql server and it is still a not null column

Any idea why this might be the case?

like image 608
atamata Avatar asked Sep 14 '26 04:09

atamata


1 Answers

Change type of PropertyArea to int?. As the docs state:

By convention, a property whose .NET type can contain null will be configured as optional, whereas properties whose .NET type cannot contain null will be configured as required. For example, all properties with .NET value types (int, decimal, bool, etc.) are configured as required, and all properties with nullable .NET value types (int?, decimal?, bool?, etc.) are configured as optional.

like image 137
Guru Stron Avatar answered Sep 16 '26 19:09

Guru Stron



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!