2

I have two projects in my solution, one is simple mvc project and the other one is web api.I have used Entity Framework. I have also used asp.net identity which generated the local db that has many columns in AspNetUsers table. Now I want to add and delete some columns from AspNetUsers table. I have included Migrations folder in my project which has configuration.cs and initial create.cs classes

CreateTable(
            "dbo.AspNetUsers",
            c => new
                {
                    Id = c.String(nullable: false, maxLength: 128),
                    Email = c.String(maxLength: 256),
                    EmailConfirmed = c.Boolean(nullable: false),
                    PasswordHash = c.String(),
                    SecurityStamp = c.String(),
                    PhoneNumber = c.String(),
                    PhoneNumberConfirmed = c.Boolean(nullable: false),
                    TwoFactorEnabled = c.Boolean(nullable: false),
                    LockoutEndDateUtc = c.DateTime(),
                    LockoutEnabled = c.Boolean(nullable: false),
                    AccessFailedCount = c.Int(nullable: false),
                    UserName = c.String(nullable: false, maxLength: 256),
                    })
            .PrimaryKey(t => t.Id)
            .Index(t => t.UserName, unique: true, name: "UserNameIndex");

I have also tried to update database using Package Manager Console but nothing happened. So how can I add another column in AspNetUsers table? Thanks in advance.

1

1 Answer 1

2

There is no need to add Codes to create the Table yourself. The Migrations can do everything for you.

public class ApplicationUser : IdentityUser
{
    ... Your Codes ...

    public string FirstName { get; set; }
    public string LastName { get; set; }
}

and just run the Code in PackageManager:

add-migration somenotehere

it will create a Migration for your database. then all you have to do is to commit the Changes to ddl.

So run this Code in PackageManager:

update-database

Hope it works.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.