0
votes

I created some classes, and configured the connection string.

But still got an error:

Unhandled Exception: System.NotSupportedException: 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.

3
How did you create the database? - Ladislav Mrnka
@LadislavMrnka the code-first feature can create database by code. - Scott 混合理论
i fixed it by Run the ‘Enable-Migrations’ command in Package Manager Console. - Scott 混合理论
@kevin you should post this as an answer to your question and mark it as correct so that other people reading it will be able to easily see your solution. - Not loved

3 Answers

0
votes
  1. Check the EF version you have, latest is 4.3.1.
  2. You also need to configure a DbContext class. check this: http://msdn.microsoft.com/en-us/data/gg685467
0
votes

i fixed it by Run the ‘Enable-Migrations’ command in Package Manager Console.

0
votes

Here is what worked for me if you are fine with deleting and recreating the database from scratch.

First, run the following commands from package manager console.

  • sqllocaldb.exe stop v11.0

  • sqllocaldb.exe delete v11.0

Next, delete the mdf and ldf files from the app_data folder of your project.

Here comes the critical part. Usually you will run update-database. If you do that the exception will still be thrown.

DO NOT Run update-database. INSTEAD directly run your project code. The EF will recreate the database.

These steps worked for me. Let me know if this helps you.