我使用Add-Migration创建了一个新的Migrations,并且能够在我的本地主机数据库上成功运行update-database。但是,当我将代码合并到git branch并尝试部署时,出现以下错误。
System.Data.Entity.Migrations.Infrastructure.AutomaticMigrationsDisabledException: 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.
因此,当我克隆分支时,我发现项目中缺少迁移文件“ 201911070247123_UpdateInsureZonetables.cs”。 ,但它存在于文件系统中。
当我查看具有先前成功迁移的请求请求时,我的构建缺少.csproj文件中的引用。 我删除并重新创建了Migration,这次更新了.csproj文件。
.csproj文件未更新是否是VS错误?但是,如果其他人遇到这种情况,我认为您可以在csproj文件中手动添加迁移参考,而不必删除并重新创建迁移。