【问题标题】:How to include existing tables into MVC5 IdentityModeld.cs ApplicationDbContext and disable migrations?如何将现有表包含到 MVC5 IdentityModeld.cs ApplicationDbContext 中并禁用迁移?
【发布时间】:2014-04-18 07:02:25
【问题描述】:

下面是我的 MVC5 App IdentityModeld.cs:

public class ApplicationUser : IdentityUser {
    public int StaffId { get; set; }
}

//public class ApplicationDbContext : 
//IdentityDbContext<User, UserClaim, UserSecret, UserLogin, Role, UserRole> {
//original: http://www.briankeating.net/?tag=/IdentityDbContext
public class ApplicationDbContext : IdentityDbContext<ApplicationUser> {

    public ApplicationDbContext() : base("DefaultConnection") {
        //Database.SetInitializer<ApplicationDbContext>(null);
        //Configuration.AutoDetectChangesEnabled = false;
    }

    protected override void OnModelCreating(DbModelBuilder modelBuilder) {
        //modelBuilder.Ignore<Staff>();
        //base.OnModelCreating(modelBuilder);
    }

    // dublicate from another DbContext
    //public DbSet<Staff> Person { get; set; }
} 

注释行导致错误:

支持“ApplicationDbContext”上下文的模型已更改 数据库已创建...

我不需要迁移。我的数据库或模型没有变化。我可以按原样从数据库中添加现有的 ApplicationDbContext 现有表吗? 我的数据库中没有 __MigrationHistory 表。

【问题讨论】:

    标签: c# ef-code-first asp.net-mvc-5 entity-framework-6


    【解决方案1】:

    您需要通过添加一个空迁移将存储在“EF 内部”的 shema 更新为当前的。
    在包管理器控制台中执行以下操作:

    Add-Migration Initial -IgnoreChanges
    

    这应该使用更新后的 EF 架构创建一个新的迁移,但 UpDown 方法为空。

    【讨论】:

    • 我得到:在程序集“应用程序”中找不到迁移配置类型。 (在 Visual Studio 中,您可以使用包管理器控制台中的 Enable-Migrations 命令添加迁移配置)。有趣的是,我的意图是完全禁止迁移
    猜你喜欢
    • 1970-01-01
    • 2021-04-18
    • 1970-01-01
    • 1970-01-01
    • 2020-11-26
    • 2017-07-28
    • 2018-01-07
    • 2016-07-15
    • 2011-09-02
    相关资源
    最近更新 更多