Ano*_*Dev 8 entity-framework entity-framework-6
正如EF Code First中常见的那样,我已经生成了一个"初始创建"迁移文件,其中找到了我的数据库的过时模型(我正在开发应用程序,因此模型仍在变化).现在我在我的代码中定义了一个"新模型",而不是为此创建新的迁移,我只想更新现有的文件,因为它仍然是最初的创建迁移.
我试过没有运气就试过这个
Update-database -targetmigration $ initialcreate
它回来了
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.
You can use the Add-Migration command to write the pending model changes to a code-based migration.
Run Code Online (Sandbox Code Playgroud)
我也试过这个,但它总是创建一个新的.cs文件
添加迁移InitialCreate
我会帮助你
Ano*_*Dev 11
在这里你可以看到我是如何解决这个问题
小心这种方法,因为在我的场景中我仍然处于开发阶段,所以我不需要保留数据库和数据.
如果要覆盖当前的"InitialCreate"文件并重新生成数据库,请按照下列步骤操作:
1)在包管理器控制台中运行:
添加迁移InitialCreate -force
2)删除物理数据库(使用SSMS,T-SQL或您的首选)
3)在包管理器控制台中运行:
Update-Database -TargetMigration:0 | update-database -force | update-database -force
如果您不关心当前的"InitialCreate"文件本身,想要创建一个新文件并重新生成数据库,请按照下列步骤操作:
1)删除当前的"InitialCreate".cs文件
3)在包管理器控制台中运行:
添加迁移InitialCreate
4)删除物理数据库(使用SSMS,T-SQL或您的首选)
4)在包管理器控制台中运行:
Update-Database -TargetMigration:0 | update-database -force | update-database -force
小智 6
我的项目解决了。
在包管理器控制台中运行: