Why Model compatibility cannot be checked?

18,540

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:

Share:
18,540
user3432681
Author by

user3432681

Updated on June 27, 2022

Comments

  • user3432681
    user3432681 almost 2 years

    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?

  • user3432681
    user3432681 about 9 years
    Thx i've do it with DropCreateDatabaseAlways. and then change back to DropCreateDatabaseIfModelChanges.