无法在Entity Framework中添加迁移

时间:2018-01-04 12:55:51

标签: c# entity-framework ef-migrations

RegisterViewModel添加了一个新字段:

[Required]
[Display(Name = "Name ")]
public string Name { get; set; }

AccountController中添加:

if (ModelState.IsValid)
{
    var user = new ApplicationUser
            {
                UserName = model.Email,
                Email = model.Email,
                Name = model.Name
            };

    var result = await UserManager.CreateAsync(user, model.Password);

    if (result.Succeeded)
    {
        await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);

        return RedirectToAction("Index", "Home");
    }

    AddErrors(result);
}

现在我想使用命令

创建一个迁移文件
add-migration newFieldName

VS生成文件,但它是空的。

public partial class newFieldName : DbMigration
{
    public override void Up()
    {
    }

    public override void Down()
    {
    }
}

更新:ApplicationUser课程

public class ApplicationUser : IdentityUser
    {
        [Required]
        public string Name { get; set; }
        public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
        {
            var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);

            return userIdentity;
        }
    }

    public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
    {
        public ApplicationDbContext()
            : base("DefaultConnection", throwIfV1Schema: false)
        {
        }

        public static ApplicationDbContext Create()
        {
            return new ApplicationDbContext();
        }
    }

0 个答案:

没有答案