简体   繁体   English

代码优先迁移错误

[英]Code-first migration error

I built my MVC C# based project using code first on local SQL Server and it all worked perfectly fine. 我首先在本地SQL Server上使用代码构建了基于MVC C#的项目,并且一切正常。 I decided to copy my intire project to a DOK and then paste it on my other computer - I literally did copy to the DOK and paste from the DOK to the other computer desktop. 我决定将自己的intire项目复制到DOK,然后将其粘贴到另一台计算机上-我确实将其复制到DOK,然后从DOK粘贴到另一台计算机桌面上。

Then I ran the project and got the followind exception when I try to access one of the models using LINQ: 然后,当我尝试使用LINQ访问其中一个模型时,我运行了项目并获得了Followind异常:

The model backing the 'BookStoreModel' context has changed since the database was created. 自创建数据库以来,支持“ BookStoreModel”上下文的模型已更改。 Consider using Code First Migrations to update the database 考虑使用代码优先迁移来更新数据库

I tried doing update-database -force yet I got there another error: 我尝试执行update-database -force但又出现了另一个错误:

Cannot find the object "dbo.Customers" because it does not exist or you do not have permissions. 无法找到对象“ dbo.Customers”,因为该对象不存在或您没有权限。

How can it be? 怎么可能? The project is running perfectly fine on the original developing machine. 该项目在原始显影机上运行良好。

1) Delete All the migrations inside of the 'Migrations' folder 1)删除“迁移”文件夹内的所有迁移

2) Delete all the tables in the database or delete database and recreate 2)删除数据库中的所有表或删除数据库并重新创建

3) Now goto package manager console and create new migration using Add-Migration 3)现在转到程序包管理器控制台,并使用“添加迁移”创建新迁移

4) Then update database using Update-Database command 4)然后使用Update-Database命令更新数据库

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM