Add column to created identity table in asp.net mvc project?

若如初见. 提交于 2019-12-24 01:59:07

问题


I use identity 2.0 in my MVC 5 project.

First time when I run the project in my DB has been created all default tables for authentication and authorization:

In AspNetUsers table I need to create additional column named LoyoutId of type integer.

My question is how can I add column to created default tables?


回答1:


You can add profile data for the user by adding more properties to your ApplicationUser class, please visit this to learn more.

In your case:

public class ApplicationUser : IdentityUser
{
     public int LoyoutId { get; set; }
}

Then open the Package Manager Console and execute following commands:

PM> Enable-migrations //You don't need this as you have already done it
PM> Add-migration Give_it_a_name //This will generate a database script file
PM> Update-database //Run script file against database.

Now, all the new properties will turn into AspNetUsers table.



来源:https://stackoverflow.com/questions/42186937/add-column-to-created-identity-table-in-asp-net-mvc-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!