EF 代码优先 - 无法检查模型兼容性,因为数据库不包含模型元数据 [英] EF code first - Model compatibility cannot be checked because the database does not contain model metadata

查看:17
本文介绍了EF 代码优先 - 无法检查模型兼容性,因为数据库不包含模型元数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I have enabled automatic migrations. Then, I deleted my whole db. Next, i executed Update-database from command console, and it recreated my db. Then, I started my application only to see this error:

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.

So what exactly is that metadata, and how can I point entity framework to it?

PS. My database contains table named MigrationsHistory.

解决方案

Here is a detailed description of the possible ways to resolve this which I wrote a while ago...
(not exactly what you're experiencing, hence not a duplicate per se, but with different scenarios in mind)

https://stackoverflow.com/a/10255051/417747

To summarize...

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

That creates a script with a 'migration difference', which you can manually apply as an SQL script on the target server database (and you should get the right migration table rows inserted etc.).

If that still doesn't work - you can still do two things...

a) remove the migration table (target - under system tables) - as per http://blogs.msdn.com/b/adonet/archive/2012/02/09/ef-4-3-automatic-migrations-walkthrough.aspx comments in there - that should fail back to previous behavior and if you're certain that your Db-s are the same - it's just going to 'trust you',

b) as a last resort I used - make a Update-Database -Script of the full schema (e.g. by initializing an empty db which should force a 'full script'), find the INSERT INTO [__MigrationHistory] records, just run those, insert them into the database, and make sure that your databases - and code match,

that should make things run in sync again.

if it helps

这篇关于EF 代码优先 - 无法检查模型兼容性,因为数据库不包含模型元数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆