IdentityServer / IdentityServer3.AspNetIdentity

ASP.NET Identity support for Thinktecture IdentityServer3
Apache License 2.0
64 stars 51 forks source link

Customizing ASPNet Identity tables #30

Closed mbhattar closed 9 years ago

mbhattar commented 9 years ago

Hi Could anyone guild me how to customize the ASPNet identity tables. I would like to add few columns to AspNetUsers table.

Here is the steps which i followed Added new properties for the CustomUser class under Thinktecture.IdentityManager.Host . when i am trying to enable migrations in Package Manager Console .. it keeps on throwing error as bellow The target context 'Thinktecture.IdentityManager.Host.CustomContext' is not constructible. Add a default constructor or provide an implementation of IDbContextFactory.

Note: I am using this repository Thinktecture.IdentityManager.AspNetIdentity

Thanks Murali

brockallen commented 9 years ago

This would be a feature of you using ASP.NET Identity -- consult the Microsoft docs on how to do this.

ryanvgates commented 8 years ago

@brockallen has a completely valid point and is correct. As a service to others that stumble here, I would like to put what I did to resolve the same issue.

In your project, there should be a folder called AspId with a class called SimpleEntities.cs. It should have the following code.

public class Context : IdentityDbContext<User, Role, string, IdentityUserLogin, IdentityUserRole, IdentityUserClaim>
{
    public Context(string connString)
        : base(connString)
    {
    }
}

You need to update it to have a default constructor, like below.

public class Context : IdentityDbContext<User, Role, string, IdentityUserLogin, IdentityUserRole, IdentityUserClaim>
{
    public Context()
        :base(Constants.ConfigurationKeys.ASPIDENTITYCONNECTIONSTRING)
    {
    }

    public Context(string connString)
        : base(connString)
    {
    }
}

Then you should be able to enable and add migrations without any errors. I would recommend adding the following code to your Startup.cs (assuming OWIN) so that you don't have to manually update your db/run migrations.

Database.SetInitializer(new MigrateDatabaseToLatestVersion<Context, Configuration>());