gpt4 book ai didi

entity-framework - EF 代码优先 - 无法检查模型兼容性,因为数据库不包含模型元数据

转载 作者:行者123 更新时间:2023-12-04 23:57:02 26 4
gpt4 key购买 nike

我已启用自动迁移。然后,我删除了我的整个数据库。接下来,我执行了 Update-database从命令控制台,它重新创建了我的数据库。然后,我启动我的应用程序只是为了看到这个错误:

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.



那么元数据究竟是什么,我如何将 Entity Framework 指向它?

附注。我的数据库包含名为 MigrationsHistory 的表.

最佳答案

这是我不久前写的解决此问题的可能方法的详细说明...
(不完全是您所经历的,因此本身不是重复的,而是考虑到不同的情况)

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

总结...

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.



如果有帮助

关于entity-framework - EF 代码优先 - 无法检查模型兼容性,因为数据库不包含模型元数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15396992/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com