C# ASP.NET添加迁移在IdentityModels.cs更改时生成空迁移
我一直在对IdentityModels.cs进行一些更改。主要是忽略几个字段并将表从“AspNetUsers”重命名为“Users”。但是,在我保存这些更改、构建项目并生成迁移之后,它只是空的 我对IdentityModels.cs所做的更改如下:C# ASP.NET添加迁移在IdentityModels.cs更改时生成空迁移,c#,asp.net,C#,Asp.net,我一直在对IdentityModels.cs进行一些更改。主要是忽略几个字段并将表从“AspNetUsers”重命名为“Users”。但是,在我保存这些更改、构建项目并生成迁移之后,它只是空的 我对IdentityModels.cs所做的更改如下: public class ApplicationUser : IdentityUser { public virtual List<Bestelling> Bestellingen { get; set; } publi
public class ApplicationUser : IdentityUser
{
public virtual List<Bestelling> Bestellingen { get; set; }
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
{
// Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
// Add custom user claims here
return userIdentity;
}
}
然后呢
update-database
但是什么也没发生,因为迁移看起来是这样的:
namespace Eindopdracht.Migrations
{
using System;
using System.Data.Entity.Migrations;
public partial class databasev2 : DbMigration
{
public override void Up()
{
}
public override void Down()
{
}
}
}
现在,在其他车型中,我添加了以下内容:
public virtual DbSet<Klant> Klants { get; set; }
这似乎不是个好办法
最终编辑
解决方案是更改configuration.cs文件并在IdentityModels.cs中进行细微更改。感谢您的帮助问题在您的
OnModelCreating
方法中
modelBuilder.Entity<IdentityUser>().
我已经像你说的那样做了更改,但是迁移仍然是空的。。我只需要在更改后构建,然后添加迁移,对吗?是的,没错。如果自上次生成迁移后数据库没有更改,则不会生成迁移。迁移是在Migrations目录中生成的,但它仍然是空的,就像之前的一样..请编辑您的问题并显示您的DbContext类?我想知道您的_MigrationHistory表是否一团糟-尝试为迁移指定一个不同的名称-
添加迁移数据库-v3
public virtual DbSet<Klant> Klants { get; set; }
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("name=DatabankEntities", throwIfV1Schema: false)
{
}
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<ApplicationUser>().Ignore(c => c.EmailConfirmed)
.Ignore(c => c.PhoneNumber)
.Ignore(c => c.PhoneNumberConfirmed)
.Ignore(c => c.TwoFactorEnabled)
.Ignore(c => c.LockoutEnabled)
.Ignore(c => c.LockoutEndDateUtc);
modelBuilder.Entity<ApplicationUser>().ToTable("Users");
}
}
namespace Eindopdracht.Migrations
{
using System;
using System.Data.Entity;
using System.Data.Entity.Migrations;
using System.Linq;
internal sealed class Configuration : DbMigrationsConfiguration<Eindopdracht.Models.DatabankBestellijn>
{
public Configuration()
{
AutomaticMigrationsEnabled = true;
}
protected override void Seed(Eindopdracht.Models.DatabankBestellijn context)
{
// This method will be called after migrating to the latest version.
// You can use the DbSet<T>.AddOrUpdate() helper extension method
// to avoid creating duplicate seed data. E.g.
//
// context.People.AddOrUpdate(
// p => p.FullName,
// new Person { FullName = "Andrew Peters" },
// new Person { FullName = "Brice Lambson" },
// new Person { FullName = "Rowan Miller" }
// );
//
}
}
}
internal sealed class Configuration : DbMigrationsConfiguration<Eindopdracht.Models.DatabankBestellijn>
internal sealed class Configuration : DbMigrationsConfiguration<Eindopdracht.Models.ApplicationDbContext>
update-database -Force
modelBuilder.Entity<IdentityUser>().
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<ApplicationUser>().Ignore(c => c.EmailConfirmed)
.Ignore(c => c.PhoneNumber)
.Ignore(c => c.PhoneNumberConfirmed)
.Ignore(c => c.TwoFactorEnabled)
.Ignore(c => c.LockoutEnabled)
.Ignore(c => c.LockoutEndDateUtc);
modelBuilder.Entity<ApplicationUser>().ToTable("Users");
}