First is the EF code. Model compatibility cannot be verified because the database does not contain model metadata

I turned on automatic migration. Then I deleted all my db. Then I ran the Update-database from the command console and it recreated my db. Then I started the application just to view this error:

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

So what is this metadata and how can I point to it the entity infrastructure?

PS. My database contains a table called MigrationsHistory .

+4
source share
5 answers

Here is a detailed description of possible solutions to this problem that I wrote some time ago ...
(not exactly what you are experiencing, therefore, not a duplicate as such, but with a different scenario)

fooobar.com/questions/94319 / ...

Summarizing...

What works for me is to use Update-Database - Script

This creates a script with a "migration difference" that you can manually apply as an SQL script in the target server database (and you should get the correct rows of the migration table, inserted, etc.).

If this still doesn't work, you can still do two things ...

a) delete the migration table (target - according to the system tables) - according to http://blogs.msdn.com/b/adonet/archive/2012/02/09/ef-4-3-automatic-migrations-walkthrough.aspx comments there - this should not return to the previous behavior, and if you are sure that your DBs are the same - it is just going to β€œtrust” you,

b) as a last resort I used - create an update database - Script a complete schema (for example, by initializing an empty db, which should force a 'full script'), find the INSERT INTO [__MigrationHistory] entries just run them, paste them into database and make sure that the databases are consistent with the code,

to make things sync again.

if he helps

+6
source

Add this to your context:

 protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Conventions.Remove<IncludeMetadataConvention>(); } 
+1
source

Disconnect the local database, for example, the example "database1.mdf" from the visual studio "server explorer", and then open the SQL server management studio, right-click on "Databases"> "Attach" and then browse the same file "database1.mdf". If you are not using, t have access, then copy and skip both the mdf and ldf files to the c drive and attach.

Then open a new query window on the sql server, then copy your ID tables as shown below.

* 'select * in [__MigrationHistory] from Database1.dbo .__ MigrationHistory' *

+1
source

I am using Entity Framework 6, SQL 2008 R2, VS 2013.
To solve this problem, use only the following procedure:

1) delete the existing db (existing database created using the EF model {code first})
2) Launch APP again.

Example request code example (in layout):
this code creates db if my model is changed and will look for the username in the user table.

 <body> @{ // Delete && Create ... Database.SetInitializer(new DropCreateDatabaseIfModelChanges<DBContext>()); var db = new DBContext(); var SearchingUser = db.Users.Where(c => c.UserName == "qwertyui"); if (SearchingUser.Count() == 0) { var User = new Users { UserName = "qwertyui",Password = "12345678" }; db.Users.Add(User); db.SaveChanges(); } } @RenderSection("scripts", required: false) @RenderBody() </body> 
0
source
  • Package Manager Console> Enable-Migrations -EnableAutomaticMigrations
  • Configure Migrations / Configuration.cs
  • Package Manager Console> Database Update
0
source

Source: https://habr.com/ru/post/1469078/


All Articles