【发布时间】:2016-08-17 12:51:08
【问题描述】:
我正在尝试向 Asp.NET Identity 创建的 AspNetUsers 表添加其他字段。我正在使用实体框架并遵循本指南。 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 方法。 当我尝试启动该站点时,我还看到这些列不存在,但我假设这是因为没有发生迁移。有谁知道为什么我的更改没有被检测到。
【问题讨论】:
-
您是否更新了 AppDbContext 以反映这些变化?如果您没有更改 AppDbContext,则 up 和 down 方法将为空。
标签: c# asp.net asp.net-mvc entity-framework