繁体   English   中英

通过迁移扩展AspNetUsers表

[英]Extending AspNetUsers table with migration

我试图将其他字段添加到由Asp.NET Identity创建的AspNetUsers表中。 我正在使用Entity Framework,并且正在遵循本指南。 http://aspmvp.com/archives/37

到目前为止,我已经在IdentityModels.cs的ApplicationUser类中添加了字段。

public class ApplicationUser : IdentityUser
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public int TimePlayed { get; set; }
    public float RevenueGenerated { get; set; }
    public string FavoriteCharity { get; set; }
    public string FavoriteGame { get; set; }
    public string ImageLocation { 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;
    }
}

我还更改了在AccountController.cs中注册所需的字段,但我认为这不会影响其工作方式。

现在,我正在尝试将更改迁移到数据库,但是由于某种原因,由Add-Migration创建的迁移具有空的Up和空的Down。 我使用的命令是:

Enable-Migrations -EnableAutomaticMigrations
Update-Database

然后我尝试

Add-Migration IdentityModels
Update-Database

两者都在迁移中创建了空的Up和Down方法。 当我尝试启动该站点时,我还看到这些列不存在,但是我认为那是因为没有进行迁移。 有谁知道为什么我的更改没有被检测到。

您的数据库性能如何? 如果使用两个数据库,请确保指向正确的数据库。 Enable-Migrations,Enable-Migrations -ContextTypeName DatabaseService.Models.MyDbContext我如何为多个上下文启用EF迁移以分离数据库所指出的那样

另外,如果您有两个数据库,我建议将它们合并为一个,

public class MySecondDBContext : IdentityDbContext<ApplicationUser>
{
    public SocialContext()
        : base("DefaultConnection")
    {


    }

添加迁移时,尝试添加-Force。

添加迁移-配置yourapp.migrations文件夹。配置migrationname-Force

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM