1

Requisites: ASP MVC 5 with Entity Framework 6 and MySQL.

So in visual studio 2013 i have created a new asp mvc 5 project and, with NuGet, installed the following packets:

  • EntityFramework (6.1.3)
  • MySql.Data (6.9.8)
  • MySql.Data.Entity (6.9.8)
  • MySql.Web (6.9.8)

I have followed this tutorial Getting Started with Entity Framework 6 Code First using MVC 5 :i have created the model, the context, the seed ecc... and setup the connection string to:

<add name="SchoolContext" providerName="MySql.Data.MySqlClient" connectionString="server=localhost;user id=root;password=passwtest;persistsecurityinfo=True;database=dbtest"/> 

Now when i try to access the Students index page i have the following exception:

{"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."} 

I see the database and the entity framework doesn't have created any tables in the dbtest schema. Why?

1 Answer 1

1

This is almost always due to using the wrong initializer. Replace DropCreateDatabaseIfModelChanges with something else like DropCreateDatabaseAlways or CreateDatabaseIfNotExists. http://www.entityframeworktutorial.net/code-first/database-initialization-strategy-in-code-first.aspx

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.