我使用 asp.net MVC 互联网应用程序开始了一个项目...我对默认代码进行了一些更改...我创建了自己的用户上下文:
public class UsersDBContext : DbContext
{
public DbSet<UserProfile> UserProfiles { get; set; }
我对 AccountModel 做了一些更改:
[Table("UserProfile")]
public class UserProfile
{
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int UserId { get; set; }
public string UserName { get; set; }
public int? test { get; set; }
}
我添加了此列测试。如您所见,此列可以为空.....但是在运行时,当我尝试注册用户时出现此错误:
无法将值 NULL 插入列“test”。列不允许空值。插入失败。
错误发生在这一行:
WebSecurity.CreateUserAndAccount(model.UserName, model.Password);
有谁知道任何解决方案?
编辑:迁移代码:
public override void Up()
{
AlterColumn("dbo.UserProfile", "test", c => c.Int());
}
public override void Down()
{
AlterColumn("dbo.UserProfile", "test", c => c.Int(nullable: false));
}