【问题标题】:__EFMigrationsHistory table remains empty though update-database command applied__EFMigrationsHistory 表仍然为空,尽管应用了 update-database 命令
【发布时间】:2019-07-15 16:50:51
【问题描述】:

我正在应用更新数据库命令。突然弹出一个错误,表明 Aspnetroles 表已经存在。 请注意,我已经多次删除了项目中的迁移文件夹。我已经了解实体框架正在尝试应用我以前的所有迁移。然后我检查了我的 [dbo].[__EFMigrationsHistory] ​​表,它是空的,如图所示 https://i.imgur.com/ed2jm8b.png

我已经尝试删除迁移文件夹并删除数据库中的所有表。但它会运行第一次迁移,创建表并且不会在数据库的迁移历史表中保留任何跟踪

另一点很有帮助的是,当我删除迁移文件夹并输入命令 enable-migrations 时,它会以黄色背景警告我:

Enable-Migrations is obsolete. Use Add-Migration to start using Migrations.

【问题讨论】:

    标签: asp.net-core entity-framework-core entity-framework-migrations


    【解决方案1】:

    EF核心不再使用Enable-Migration。如果你想添加迁移,你需要使用下面的代码:

    Add-Migration MigrationName
    Update-Database
    

    参考https://docs.microsoft.com/en-us/ef/core/managing-schemas/migrations/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-17
      • 1970-01-01
      • 2023-04-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多