[C#] The model backing the 'EFDbContext' context has changed since the database was created......

  • 538
  • 0

錯誤訊息:

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).

發生原因

資料庫欄位有異動

造成資料庫內的欄位與專案上的Model欄位有所衝突

因而產生此錯誤

解決方式

在套件管理器主控台輸入 > Add-Migrations 即會自動產生程式

該程式內容是將資料庫的欄位異動成與Model一樣

因此可由此判定資料庫上與Model內欄位的差異

再依各自需求看是要執行 > Update-Migrations 異動資料庫內的欄位

或是要異動Model來符合資料庫

Write By Charley Chang 


新手發文,若有錯誤還請指教,
歡迎留言或Mail✉給我

創用 CC 授權條款


本著作係採用創用 CC 姓名標示-非商業性-相同方式分享 4.0 國際 授權條款授權.