解决Entity Framework Code First 的问题——Model compatibility cannot be checked because the database does not contain model metadata
这两天在虚拟机里重新学习了一下ASP.NET MVC,然后就在Codeplex网站里面找到MVCMusicStore的代码进行研究,跟着它的代码一步一步学习下去。结果在使用EF的时候映射数据的时候,出现了下面的问题。如图:
错误的提示为: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.
解决方法:
USE [master] GO /****** Object: Database [DBname] ******/ ALTER DATABASE [DBname] SET SINGLE_USER WITH ROLLBACK IMMEDIATE ALTER DATABASE [DBname] SET SINGLE_USER WITH NO_WAIT DROP DATABASE [DBname] GO
DBname 即为你的数据库名称,执行完上面的这段Sql语句,上面出现的问题就解决了。