该模型支持了“ApplicationDbContext”背景已经改变,因为在创建数据库 [英] The model backing the 'ApplicationDbContext' context has changed since the database was created

查看:853
本文介绍了该模型支持了“ApplicationDbContext”背景已经改变,因为在创建数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我还没有看到这个错误在其他地方,我想它不是一个重复,所以请首先阅读整个局势

然后我想的更新我的模型类的(在 App类并更新,现在留下评论),我将列出一个每一件事情是工作得很好下面和吊杆我有这个丑陋的错误。


该模式支持的ApplicationDbContext背景已经改变,因为在创建数据库。请考虑使用code首先迁移到更新数据库(<一href="http://go.microsoft.com/fwlink/?LinkId=238269">http://go.microsoft.com/fwlink/?LinkId=238269).在System.Data.Entity.CreateDatabaseIfNotExists 1.InitializeDatabase(TContext上下文)在System.Data.Entity.Internal.InternalContext&LT;&GT; c__DisplayClassf 1.b_的 E()在System.Data.Entity.Internal.InternalContext.PerformInitializationAction(动作动作)在System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization()在System.Data.Entity.Internal.LazyInternalContext.b 的_4 (InternalContext c)在System.Data.Entity.Internal.RetryAction 1.PerformAction(TInput输入)在System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(动作 1的动作)在System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase()在System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(类型的EntityType)在System.Data.Entity.Internal.Linq.InternalSet 1 .Initialize()在System.Data.Entity.Internal.Linq.InternalSet 1.Include(字符串路径)的System.Data.Entity.Infrastructure.DbQuery 1.Include(字符串路径),在System.Data.Entity.QueryableExtensions.Include [T](IQueryable的 1来源,字符串路径),在System.Data.Entity.QueryableExtensions.Include [T,TProperty](IQueryable的 1来源,例pression 1路)在Microsoft.AspNet.Identity.EntityFramework.UserStore 6.GetUserAggregateAsync(出pression 1过滤器)的Microsoft.AspNet.Identity.EntityFramework.UserStore 6.FindByNameAsync(用户名字符串)在Microsoft.AspNet.Identity.UserManager 2.FindByNameAsync(字符串用户名)在Microsoft.AspNet.Identity.UserManager`2.d_的 12.MoveNext()---由previous位置的堆栈跟踪,其中引发异常---在System.Runtime.CompilerServices.TaskAwaiter结束.ThrowForNonSuccess(任务的任务)在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(工作任务)在ControlPanel.Web.Controllers.AccountController.d 的_2.MoveNext()在d:\项目\完全\控制面板\ ControlPanel.Web \控制器\ AccountController.cs:56行

首先我想这可能是一个移民问题,,所以我完全放弃了数据库,我重新启用迁移,增加了一个初始化的迁移和更新使用该数据库

 更新数据库-force -verbose
 

每一件事情远远没有投诉,,但每当我试图登录我的网站,我得到了previous错误,,我做移植的事情十倍左右,而能够解决的问题。

下面是我的领域类(模型):

 公共类应用
{
    [键]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)
    公共虚拟INT的AppId {获得;组; }
    //[需要]
    公共虚拟字符串FacebookId {获得;组; }
    //[需要]
    公共虚拟字符串秘密{获得;组; }
    公共虚拟目录&lt;使用者&GT;用户{获得;组; }
    公共虚拟目录&LT;邮政&GT;帖子{获得;组; }
    //公共虚拟ApplicationUser联系{获得;组; }
}

公共类岗位
{
    [键]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)
    公共虚拟INT PostId {获得;组; }
    公共虚拟字符串内容{获得;组; }
    公共虚拟字符串连接{获得;组; }
    公共虚拟字符串图像{获得;组; }
    公共虚拟BOOL IsSpecial {获得;组; }
    //[需要]
    公共虚拟应用应用{获得;组; }
    //[需要]
    公共虚拟日期时间? PublishDate {获得;组; }
}
 

 公共类用户
{
    [键]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)
    公共虚拟INT用户ID {获得;组; }

    [最大长度(500)]
    公共虚拟字符串FacebookId {获得;组; }

    [最大长度(500)]
    公共虚拟字符串标记{获得;组; }

    //[需要]
    公共虚拟应用应用{获得;组; }
}
 

下面是我的IdentityModels:

 公共类ApplicationUser:IdentityUser
{
    公共虚拟目录&LT;应用&GT;应用程序{获得;组; }
    公共BOOL?是premium {获得;组; }
    [数据类型(DataType.Date)
    公开日期时间? LastPublishDateTime {获得;组; }
}

公共类ApplicationDbContext:IdentityDbContext&LT; ApplicationUser&GT;
{
    公共ApplicationDbContext()
        :基地(DCON)
    {
    }
    保护覆盖无效OnModelCreating(DbModelBuilder模型构建器)
    {
        base.OnModelCreating(模型构建器);
        modelBuilder.Entity&LT; IdentityUser&GT;()ToTable(管理员)。
        modelBuilder.Entity&LT; ApplicationUser&GT;()ToTable(管理员)。
        modelBuilder.Entity&其中; IdentityUserRole&GT;()ToTable(AdminRoles);
        modelBuilder.Entity&LT; IdentityUserLogin&GT;()ToTable(登录)。
        modelBuilder.Entity&LT; IdentityUserClaim&GT;()ToTable(声明)。
        modelBuilder.Entity&LT; IdentityRole&GT;()ToTable(角色)。
    }
}
 

解决方案

它是这样一个奇怪的错误,,这不是我的错误在最后,这是微软的,,我装的是实体框架的$ P $对发布的版本,这是负责这个错误,,当我升级到稳定版本是disapperared ,,谢谢大家相信我,当我问到这个问题,我搜索像一个星期左右,其解决方案,所以我pretty的肯定,这个问题是不是其他地方:实体framework.dll的导致问题是6.0.2版本,如果有帮助

First of all i have not seen this error anywhere else and i guess its not a replicate so please read the whole situation first

Every thing was working just fine then i tried to update one of my model classes ( the App class and the update is now left commented ) which i will be listing below and boom I had this ugly error.


The model backing the 'ApplicationDbContext' context has changed since the database was created. Consider using Code First Migrations to update the database (http://go.microsoft.com/fwlink/?LinkId=238269). at System.Data.Entity.CreateDatabaseIfNotExists1.InitializeDatabase(TContext context) at System.Data.Entity.Internal.InternalContext.<>c__DisplayClassf1.b_e() at System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action) at System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization() at System.Data.Entity.Internal.LazyInternalContext.b_4(InternalContext c) at System.Data.Entity.Internal.RetryAction1.PerformAction(TInput input) at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action1 action) at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase() at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) at System.Data.Entity.Internal.Linq.InternalSet1.Initialize() at System.Data.Entity.Internal.Linq.InternalSet1.Include(String path) at System.Data.Entity.Infrastructure.DbQuery1.Include(String path) at System.Data.Entity.QueryableExtensions.Include[T](IQueryable1 source, String path) at System.Data.Entity.QueryableExtensions.Include[T,TProperty](IQueryable1 source, Expression1 path) at Microsoft.AspNet.Identity.EntityFramework.UserStore6.GetUserAggregateAsync(Expression1 filter) at Microsoft.AspNet.Identity.EntityFramework.UserStore6.FindByNameAsync(String userName) at Microsoft.AspNet.Identity.UserManager2.FindByNameAsync(String userName) at Microsoft.AspNet.Identity.UserManager`2.d_12.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at ControlPanel.Web.Controllers.AccountController.d_2.MoveNext() in d:\Projects\FULL\Control Panel\ControlPanel.Web\Controllers\AccountController.cs:line 56

At first i thought it might be a migrations problem,, so i dropped the database entirely, i re-enabled the migrations, added an Init migration and updated the database using

update-database -force -verbose

every thing goes well no complaints,, however whenever i try to log in to my site i get the previous error,, i did the migration thing about ten times without being able to solve the problem..

here are my domain classes ( models ):

public class App
{
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public virtual int AppId { get; set; }
    //[Required]
    public virtual string FacebookId { get; set; }
    //[Required]
    public virtual string Secret { get; set; }      
    public virtual List<User> Users { get; set; }
    public virtual List<Post> Posts { get; set; }      
    //public virtual ApplicationUser Admin { get; set; }
}

public class Post
{
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public virtual int PostId { get; set; }
    public virtual string Content { get; set; }
    public virtual string Link { get; set; }
    public virtual string Image { get; set; }
    public virtual bool IsSpecial { get; set; }
    //[Required]
    public virtual App App { get; set; }
    //[Required]
    public virtual DateTime? PublishDate { get; set; }
}

public class User
{
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public virtual int UserId { get; set; }

    [MaxLength(500)]
    public virtual string FacebookId { get; set; }

    [MaxLength(500)]
    public virtual string Token { get; set; }

    //[Required]
    public virtual App App { get; set; }
}

here are my IdentityModels:

public class ApplicationUser : IdentityUser
{
    public virtual List<App> Apps { get; set; }
    public bool? IsPremium { get; set; }
    [DataType(DataType.Date)]
    public DateTime? LastPublishDateTime { get; set; }
}

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
    public ApplicationDbContext()
        : base("dCon")
    {
    }
    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);
        modelBuilder.Entity<IdentityUser>().ToTable("Admins");
        modelBuilder.Entity<ApplicationUser>().ToTable("Admins");
        modelBuilder.Entity<IdentityUserRole>().ToTable("AdminRoles");
        modelBuilder.Entity<IdentityUserLogin>().ToTable("Logins");
        modelBuilder.Entity<IdentityUserClaim>().ToTable("Claims");
        modelBuilder.Entity<IdentityRole>().ToTable("Roles");
    }
}

解决方案

It was such a strange error,, It wasn't my error at the end, it was Microsoft's,, I installed the Entity framework the " pre-release" version and it was responsible for this error,, when i upgraded to the stable release it disapperared,, thank you everyone believe me when i asked this question i searched like for a week or so for its solution so i am pretty sure that this problem isn't anywhere else : the version of entity framework.dll that caused the problem was 6.0.2 if it helps.

这篇关于该模型支持了“ApplicationDbContext”背景已经改变,因为在创建数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆