Why Model compatibility cannot be checked?

asp.net c# entity-framework

Question

I had to work further from a ex collega. So I run the asp.net solution without database. and it created a database. I think this is Code First or Code First Migrations.

Then I tried some tests in de UI and get this message:

An exception of type 'System.NotSupportedException' occurred in EntityFramework.dll but was not handled in user code

Additional information: Model compatibility cannot be checked because the database does not contain model metadata. Model compatibility can only be checked for databases created using Code First or Code First Migrations.

This is the code where de message come from.

public class TemInitializer : System.Data.Entity.DropCreateDatabaseIfModelChanges<ApplicationDbContext>
{
    public override void InitializeDatabase(ApplicationDbContext context)
        {
            base.InitializeDatabase(context);
        }
}

Can anybody tell me how to solve this or where i need to look?

1
3
3/30/2015 2:53:50 PM

Accepted Answer

The DropCreateDatabaseIfModelChanges initializer drops and recreates the database if the database schema no longer matches the classes in your code. It determines "if model changes" by looking at your classes and by looking at a table called _MigrationHistory in the database. If there is no such table, it throws the exception in the question.

So to solve this, you can:

13
3/30/2015 3:25:53 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow