【问题标题】:Model column doesn't exist in __EFMigrationsHistory of EF CoreEF Core 的 __EFMigrationsHistory 中不存在模型列
【发布时间】:2019-07-07 10:39:41
【问题描述】:

我正在以代码优先的方式使用 EF Core。一切都像 EF 6.0 一样运行良好,用于迁移、创建表、关系等。但是,__EFMigrationsHistory 表缺少一件事,应该有一个“模型”列来存储迁移的二进制数据。运行 update-database 命令时未创建模型列。请检查我下面的代码和图片。

DbContext

namespace ProfileCore.DataAccess
{
    /// <summary>
    /// Represents DB Context (DbSet, Configuration and common activities)
    /// </summary>
    public partial class ProfileCoreDbContext: DbContext, IDbContext
    {
        #region Ctor

        public ProfileCoreDbContext(DbContextOptions<ProfileCoreDbContext> options) : base(options)
        {
        }
        #endregion

        #region Authentications DbSets
        public virtual DbSet<UserType> UserType { get; set; }
        #endregion

        #region Utilities

        /// <summary>
        /// Further configuration the model
        /// </summary>
        /// <param name="modelBuilder">The builder being used to construct the model for this context</param>
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {

        }
        #endregion

    }
}

更新命令:

Update-Database -Migration 20190703213515_FirstMigration

【问题讨论】:

  • “EF Core 中是否弃用了模型列?” 不知道您为什么关心,但看起来确实如此。和现在的操作系统开发一样,没有太多相关文档,可以从HistoryRow类的属性中获取默认列。

标签: entity-framework entity-framework-core


【解决方案1】:

在 EF Core 中,__EFMigrationsHistory 表只有两列,因此屏幕截图中显示的内容是正确的。

当您运行Update-Database 时,不必包含迁移的时间戳前缀。因此,如果您添加了一个名为 FirstMigration 的迁移,您最终可能会得到一个文件 20190703213515_FirstMigration.cs,但您要运行的是这个

Update-Database -Migration FirstMigration

【讨论】:

  • 谢谢,Ray,我希望 Model 列像 EF 6.0 一样以二进制格式存储每个迁移记录,因此我可以回滚迁移。
  • 没问题。希望这会有所帮助:)
猜你喜欢
  • 2017-03-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-28
  • 1970-01-01
  • 1970-01-01
  • 2016-12-19
  • 2022-11-17
相关资源
最近更新 更多