千家信息网

EF数据库迁移

发表于:2024-09-22 作者:千家信息网编辑
千家信息网最后更新 2024年09月22日,开启codefirst迁移命令:Enable-Migrations -ContextTypeName BlogEntitiesBlogEntities(上下文,继承DbContext的那个类)更新数据
千家信息网最后更新 2024年09月22日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:



0