天天看點

EF-CodeFirst資料庫遷移時可能出現的幾種錯誤- The EntityFramework package is not installed on project 'MovieEF'

相關: EF-CodeFirst實作過程+資料庫遷移

enable-Migrations -Force

Add-Migration demo

最後再次執行:Update-Database -Force

codefirst在做資料庫遷移的可能出現的錯誤:

** 1. The EntityFramework package is not installed on project 'MovieEF'.**

EF-CodeFirst資料庫遷移時可能出現的幾種錯誤- The EntityFramework package is not installed on project 'MovieEF'

The EntityFramework package is not installed on project 'MovieEF'.

我是在手動引入(也就是非Nuget安裝)EF的情況下出現這種錯誤

** Solution:** 通過Nuget方式重新安裝EntityFramework

** 2. 不能将值 NULL 插入列 'Genre',表 '2017_03_14MVC+EF.dbo.Movies';列不允許有 Null 值。UPDATE 失敗。

語句已終止。 **

EF-CodeFirst資料庫遷移時可能出現的幾種錯誤- The EntityFramework package is not installed on project 'MovieEF'

不能将值 NULL 插入列 'Genre',表 '2017_03_14MVC+EF.dbo.Movies';列不允許有 Null 值。UPDATE 失敗。

語句已終止

** 原因:** 資料庫中已經存在的資料在"Genre"列有NULL值

** Solution: ** 到資料庫把這條資料删除或者給個值

EF-CodeFirst資料庫遷移時可能出現的幾種錯誤- The EntityFramework package is not installed on project 'MovieEF'

db.PNG

資料庫中已經存在XX表

我不知道問題的原因,但是對于比較小的更改可以直接自己寫語句,并且知道自己做了哪些更改的情況下:

public override void Up()
        {
            AddColumn("dbo.Teachers", "UserID", c => c.String());
            AddColumn("dbo.Managers", "UserID", c => c.String());
        }
        
        public override void Down()
        {
        }