2016-04-24 62 views
0

我想将其他字段添加到由Asp.NET标识创建的AspNetUsers表中。我正在使用实体框架并遵循本指南。 http://aspmvp.com/archives/37使用迁移扩展AspNetUsers表

到目前为止,我已经在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注册所需要的领域,但我不认为这会影响到如何工作的。

现在我试图将更改迁移到我的数据库,但由于某种原因,通过添加迁移创建的迁移具有空的Up和空Down。我用的命令是:

Enable-Migrations -EnableAutomaticMigrations 
Update-Database 

然后我试图

Add-Migration IdentityModels 
Update-Database 

两个创建在迁移空向上和向下的方法。 当我尝试启动网站时,我也看到列不存在,但我认为这是因为没有发生迁移。有没有人看到我的更改没有被检测到。

回答

0

你有manay数据库吗?如果您使用两个数据库,请确保您指向正确的一个。 Enable-Migrations,Enable-Migrations -ContextTypeName DatabaseService.Models.MyDbContextHow do I enable EF migrations for multiple contexts to separate databases?

同时指出,如果你有两个数据库,我会建议他们合并为一个,将迁移时

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


    } 
0

尝试增加-Force。

Add-Migration -configuration yourapp.migrationsfolder.Configuration migrationname-Force