I have an ASP.NET MVC project using EF code first and migrations.
I am trying to add a new property to a class. For that I create the migration code in order to add the specific column in the table related to that class.
My migration code is the following:
public partial class Add_DataRequisicao_to_BiblRequisicao : DbMigration
{
public override void Up()
{
AddColumn("dbo.BiblRequisicoes", "DataRequisicao", c => c.String(nullable: false, defaultValue: "01/01/1900 00:00"));
}
public override void Down()
{
DropColumn("dbo.BiblRequisicoes", "DataRequisicao");
}
}
And the property to add to the class is the following:
[Required]
[Display(Name = "Data Requisição")]
public string DataRequisicao { get; set; }
When I publish the project and go to the project web site, I get the following error 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.
Inspecting the database, I see that the migration was run with success because the column was created. In the migration table, there also is a new entry that indicates that the migration ran.
The migration entry:
MigrationId: 201704261436437_Add_DataRequisicao_to_BiblRequisicao
ContextKey: WebAppInvestigacaoMultimedia.Migrations.Configuration
Model: 0x1F8B0800000...
ProductVersion: 6.1.3-40302
I don't understand why I get the error message if the migration ran with success and the name and the type of the property is the same as the add column of the table.
Add-Migrations
, which means code-based migration. Use-Verbose -Script
flag in Package Manager Console to see DB scripts and steps to perform migration process. – Tetsuya Yamamoto