MVC中EF代碼優先問題
阿新 • • 發佈:2017-07-13
管理 mvc isa 執行 ont 練習 無法連接 his onf
You can use the Add-Migration command to write the pending model changes to a code-based migration.
在練習Mvc項目時,提示如下數據庫錯誤:
The model backing the ‘EFDbContext‘ context has changed since the database was created. Consider using Code First Migrations to update the database (http://go.microsoft.com/fwlink/?LinkId=238269).
按上述鏈接要求,在程序包管理控制臺執行:Enable-Migrations 後,
生成對應DAL目錄內生成 Mirgrations新目錄,
再執行 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.
項目仍無法連接數據庫,
後直接清除數據庫內的 [__MigrationHistory]表數據,
問題成功解決。
MVC中EF代碼優先問題