您的位置:首页 > 其它

Unable to update database to match the current model!

2017-11-10 21:48 411 查看
PM> enable-migrations
Checking if the context targets an existing database...
Code First Migrations enabled for project BTCheck.

PM> add-migration init
Scaffolding migration 'init'.
The Designer Code for this migration file includes a snapshot of your current Code First model. This snapshot is used to calculate the changes to your model when you scaffold the next migration. If you make additional changes to your model that you want to include in this migration, then you can re-scaffold it by running 'Add-Migration init' again.

PM> update-database
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
No pending explicit migrations.
Unable to update database to match the current model because there are pending changes and automatic migration is disabled. Either write the pending model changes to a code-based migration or enable automatic migration. Set DbMigrationsConfiguration.AutomaticMigrationsEnabled to true to enable automatic migration.
You can use the Add-Migration command to write the pending model changes to a code-based migration.

按照正常的codefirst的执行顺序,代码也没有问题,但就是无法更新到数据库。

原因在于在更新数据库之前没有生成解决方案,只要build一下再次update-database一下就可以了。

PM> update-database
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
Applying explicit migrations: [201711101328231_init].
Applying explicit migration: 201711101328231_init.
Running Seed method.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐