EF Core的__EFMigrationsHistory

时间:2019-07-06 06:59:48

标签: entity-framework entity-framework-core

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

enter image description here

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

1 个答案:

答案 0 :(得分:0)

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

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

Update-Database -Migration FirstMigration