Entity Framework does not update my database

Asked

Viewed 308 times

1

I’m using EF6

And it turns out that when I use Update-Database it does not update my database.

For example

I have my model:

public class Cliente 
{
   public int Id {get;set}
   public string Nome {get;set;}
}

If I add a new property:

public string CNPJ {get;set;}

And rotate Update-Database or Update-Database -force It does not update, and while accessing it error and informs to do Migrations

What I’ve done is:

enable-migrations
add-migration InitialCreate

In the file of Configuration setei o AutomaticMigrationsEnabled:

   public Configuration()
    {
        AutomaticMigrationsEnabled = true;
    }
  • With AutomaticMigrationsEnabled you don’t need to generate Migrations.

1 answer

1

There are some ways to solve.

1. Revert the bank to a Migration that you know works

This is the case for projects with manual generation of Migrations. Use the following command:

Update-Database -TargetMigration:NomeDaMigrationSemOPontoCsNoFinal

2. Erase the development bank

No mercy. If you are SQL Server, by Management Studio, enter the database and delete the entire database (right-click > Delete or Delete). Try running the Update-Database again.

If you find it necessary, make a backup of the bank, but it is usually not.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.