In database there is a column Created
, it has a default GETDATE()
so it is assigned on insert automatically. This column is currently not in the model class. When I try to add the property to the model class:
[Required, DatabaseGenerated(DatabaseGeneratedOption.Computed)]
public DateTime Created { get; set; }
and run update-database
, it results in the message:
Unable to update database to match the current model because there are pending changes and automatic migration is disabled. Either write the pending model changes to a code-based migration or enable automatic migration. Set DbMigrationsConfiguration.AutomaticMigrationsEnabled to true to enable automatic migration. You can use the Add-Migration command to write the pending model changes to a code-based migration.
When I tried to allow automatic migration, EF tries to create the DB column Created
, but this fails, because the column is already there.
Is there a way to correct the model class?