Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Model compatibility cannot be checked?

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?

like image 213
user3432681 Avatar asked May 10 '26 09:05

user3432681


1 Answers

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:

  • Use a different initializer (such as DropCreateDatabaseAlways) or
  • Make sure that there is a _MigrationHistory table in your database, by enabling Entity Framework code first migrations.
like image 64
OJ Raqueño Avatar answered May 12 '26 22:05

OJ Raqueño



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!