Entity Framework does not update my database

1

I'm using EF6

And it happens 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 run Update-Database or Update-Database -force It does not update, and when it accesses the error and informs to do the migrations

What I already did was:

enable-migrations
add-migration InitialCreate

In the file of Configuration set AutomaticMigrationsEnabled :

   public Configuration()
    {
        AutomaticMigrationsEnabled = true;
    }
    
asked by anonymous 29.01.2015 / 00:44

1 answer

1

There are a few 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. Delete the development bank

No problem. If it is SQL Server, through Management Studio, enter the database and delete the entire database (right-click> Delete or Delete). Try running Update-Database again.

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

    
29.01.2015 / 03:36