Brux88
Brux88

Reputation: 138

Ef 6.1 code first migration decimal? to decimal

everyone I'm using ef 6.1 code first with the automatic migration enabled. If, after you have created the db change a property to decimal? in decimal. Qunado tries to update the db I get the following error: An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in EntityFramework.dll .... The column is not nullable. UPDATE fails.

How can I fix all automatically?

Upvotes: 1

Views: 676

Answers (1)

Stefan
Stefan

Reputation: 17658

It seems there are already null values in your database. So there is a conflict between the not null restriction and the data.

Run the

add-migration

command in the nuget console to add a migration.

Use that migration to fill the future non nullable field with a value and then mark the field non nullable.

The migration will not be generated automatically, but depending on your setup, it will be automatically deployed/migrated.

A nice article about automatic migrations can be found here: http://coding.abel.nu/2012/03/ef-migrations-command-reference/

Upvotes: 2

Related Questions