首先,在其他任何地方都没有看到此错误,我想这不是重复错误,因此请先阅读整个情况。
一切工作都很好,然后我尝试更新我的一个模型类(App类,现在对更新进行评论),我将在下面列出。和繁荣我有这个丑陋的错误。
自创建数据库以来,支持“ ApplicationDbContext”上下文的模型已更改。考虑使用“代码优先迁移”来更新数据库(http://go.microsoft.com/fwlink/?LinkId=238269)。System.Data.Entity.CreateDatabaseIfNotExists
1.InitializeDatabase(TContext context) at System.Data.Entity.Internal.InternalContext.<>c__DisplayClassf
上的System.Data.Entity.Internal.InternalContext.PerformInitializationAction(b)处的System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization()处的Action动作。 System.Data.Entity.Internal.RetryAction1.PerformAction(TInput input) at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action
1动作的Internal.LazyInternalContext.b__4(System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase()的System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type)实体类型)位于System.Data.Entity.Internal.Linq.InternalSet1.Initialize() at System.Data.Entity.Internal.Linq.InternalSet
1.System.Data.Entity.Infrastructure.DbQuery的1.Include(String路径),Microsoft.AspNet.Identity的1.Include(String path) at System.Data.Entity.QueryableExtensions.Include[T](IQueryable
System.Data.Entity.QueryableExtensions.Include [T,TProperty](IQueryable1 source, Expression
1路径)处的String路径。6.GetUserAggregateAsync(Expression
Microsoft.AspNet.Identity.EntityFramework.UserStore6.FindByNameAsync(String userName) at Microsoft.AspNet.Identity.UserManager
2.FindByNameAsync(String userName)在Microsoft.AspNet.Identity.UserManager`2.d__12.MoveNext()的EntityFramework.UserStore 1筛选器)---从上一个位置开始的堆栈跟踪结束在d的System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)的System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)的ControlPanel.Web.Controllers.AccountController.d__2.MoveNext()中引发了异常:\ Projects \ FULL \控制面板\ ControlPanel.Web \ Controllers \ AccountController.cs:第56行
起初我以为可能是迁移问题,所以我完全删除了数据库,重新启用了迁移,然后添加了Init迁移并使用
update-database -force -verbose
一切顺利,没有任何抱怨,但是,每当我尝试登录到我的网站时,我都会收到先前的错误。我无法解决问题大约做了十次迁移。
这是我的领域类(模型):
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; }
}
这是我的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");
}
}