EF數據庫遷移

開啓codefirst遷移命令:

Enable-Migrations -ContextTypeName BlogEntities

BlogEntities(上下文,繼承DbContext的那個類)



更新數據庫命令:

Update-Database -Verbose


新增變更類文件命令:

Add-Migration AddBolg

AddBolg(生成的文件名)


Add-Migration AddBolg-IgnoreChanges:對現有數據庫進行遷移



自動數據遷移:

將Configuration的AutomaticMigrationsEnabled設置爲true


當設置自動數據遷移之後,放模型變更只需要執行Update-Database -Verbose命令

注意:模型有刪減的話需要先執行Add-Migration命令再執行Update-Database -Verbose命令




注意,當執行Enable-Migrations -ContextTypeName BlogEntities命令是報如下錯誤時需要使用NuGet添加EntityFramework:

wKiom1gIZ6OA0yL9AAAf3Cw-kO0136.png



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章