【问题标题】:Add column to created identity table in asp.net mvc project?在 asp.net mvc 项目中将列添加到创建的身份表?
【发布时间】:2017-02-12 11:19:58
【问题描述】:

我在我的 MVC 5 项目中使用身份 2.0。

当我第一次在我的数据库中运行项目时,已经创建了所有用于身份验证和授权的默认表:

在 AspNetUsers 表中,我需要创建名为 LoyoutId 的整数类型的附加列。

我的问题是如何将列添加到创建的默认表中?

【问题讨论】:

    标签: asp.net-mvc asp.net-identity


    【解决方案1】:

    您可以通过向ApplicationUser 类添加更多属性来为用户添加个人资料数据,请访问this 了解更多信息。

    在你的情况下:

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

    然后打开包管理器控制台并执行以下命令:

    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.
    

    现在,所有新属性都将变成AspNetUsers 表。

    【讨论】:

    • 感谢您的发布。如果我需要创建一个表并将其与现有的用户表相匹配怎么办?
    • 不客气!你什么意思?没有帮助我评论中的链接?
    • 错误:“数据库中已经有一个名为 'AspNetRoles' 的对象”
    • 您需要先运行 Add-Migration InitialMigrations -IgnoreChanges
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-25
    • 1970-01-01
    • 2010-10-31
    • 1970-01-01
    相关资源
    最近更新 更多