我的 MVC 5 项目使用代码优先方法创建数据库。但是在启用迁移后,我收到错误
Migrations is enabled for context 'ApplicationDbContext' but the database does not exist or contains no mapped tables. Use Migrations to create the database and its tables, for example by running the 'Update-Database' command from the Package Manager Console.
但是,如果我删除迁移文件夹,则错误已解决,但我无法使用迁移。请帮忙。我附上错误的屏幕截图。
我为 add-migration
运行命令,然后为 update-database
运行命令。那确实帮助了我。但是,如果我更改连接字符串并再次运行该项目,那么它不会创建数据库,直到迁移文件夹未被删除。
最佳答案
在您可以使用您的数据库之前,您需要创建一个迁移,它使用 Add-Migration
命令描述您的数据库结构,然后使用 更新您的数据库以匹配您当前的模型>更新数据库
命令。
您可能会找到 this tutorial有用。
关于c# - 如果第一次使用代码优先方法会出现迁移错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33764867/