实体框架“Code First”不创建数据库表

时间:2022-04-10 16:29:21

I've created my objects in ASP.NET MVC4, and after running the application, only UserProfile table is auto created, not the other one corresponding my class.

我在ASP.NET MVC4中创建了我的对象,在运行应用程序之后,只有UserProfile表是自动创建的,而不是另一个对应我的类。

Followed this advice: Entity Framework 4.1 Code First not creating tables and got this error:

遵循以下建议:实体框架4.1代码首先不创建表并得到此错误:

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.

无法检查模型兼容性,因为数据库不包含模型元数据。只能检查使用Code First或Code First Migrations创建的数据库的模型兼容性。

Question 1: What is the correct way to do this in Code First approach?

问题1:在Code First方法中执行此操作的正确方法是什么?

Question 2: Why is the built-in UserProfile created, and not the table for my object? What makes the difference?

问题2:为什么创建了内置的UserProfile,而不是我的对象的表?有什么区别?

1 个解决方案

#1


1  

Please read my answer here ... same situation I think. UserProfile table created, others not created. My guess is that you've switched to an actual MSSQL DB and not a local DB, but have not pointed your WebSecurity DB initialization to the new database.

请在这里阅读我的答案......我认为同样的情况。创建了UserProfile表,未创建其他表。我的猜测是你已经切换到实际的MSSQL DB而不是本地数据库,但是没有将WebSecurity DB初始化指向新数据库。

#1


1  

Please read my answer here ... same situation I think. UserProfile table created, others not created. My guess is that you've switched to an actual MSSQL DB and not a local DB, but have not pointed your WebSecurity DB initialization to the new database.

请在这里阅读我的答案......我认为同样的情况。创建了UserProfile表,未创建其他表。我的猜测是你已经切换到实际的MSSQL DB而不是本地数据库,但是没有将WebSecurity DB初始化指向新数据库。