如何 AspNetCore.Identity 自定义带有约束的字段。
How to AspNetCore.Identity Custom Fields With Constraints.
我想将自定义字段添加到 AspNetCore.Identity 并且已经这样做了
public class ApplicationUser : IdentityUser
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
我试过这样做
public class ApplicationUser : IdentityUser
{
[Required]
public string FirstName { get; set; }
[Required]
public string LastName { get; set; }
}
但这没有任何作用。
一般来说,如果数据库 table 不为空,则无法添加 "Not Null" 的新列。
现在您可以清空数据库并重新创建这些字段,或者手动将它们更改为非空,这样就没问题了。
当然,如果有记录并且您不想丢失它们,则需要在 First 和 Last name
列中填写一些值
我想将自定义字段添加到 AspNetCore.Identity 并且已经这样做了
public class ApplicationUser : IdentityUser
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
我试过这样做
public class ApplicationUser : IdentityUser
{
[Required]
public string FirstName { get; set; }
[Required]
public string LastName { get; set; }
}
但这没有任何作用。
一般来说,如果数据库 table 不为空,则无法添加 "Not Null" 的新列。
现在您可以清空数据库并重新创建这些字段,或者手动将它们更改为非空,这样就没问题了。 当然,如果有记录并且您不想丢失它们,则需要在 First 和 Last name
列中填写一些值