none
Why can't I add a custom field to AspNetUsers?

    Question

  • I'm using Visual Studio 2013, premium.

    MVC 5, Identity Framework 2.0.

    Hello.  I have inherited an mvc5 project and it uses Entity Framework.  Currently there is 1 database (Code first) for this project.  This Database has 2 data contexts.  A data context for the standard operation and a data context for the Identity 2.0 functions. I have enabled migrations for both.  I want to add a custom field to the AspNetUsers table but I can't.   Here is what I'm doing.

    1. Add the new field to the IdentityModel.cs file.  ie: public DateTime BirthDate { get; set; } 

    2. open up the package manager console and run Add-Migration "Birthdate".

    3. The migration is created.

    4. run Update-Database from the package manager console. 

    5. I get an error that says my table already exists.

    So, the field is never added.  But there are a few more things!!!  I look at the migration code that is created and it DOESN'T contain my new field.    ALSO the migration code tries to re-create all the tables. 

    I'm not sure why this is happening.  I've created a totally clean test project and it works as expected.  The migration code looks right and it just tries to update the table to include the field.  It doesn't try to re-crate the table. 

    There are several things going on here... but I don't understand them.  I'm stuck at this roadblock and trying hard to get some insight.  Any help would be great.

    Thanks.

    Thursday, December 4, 2014 6:44 PM

Answers

  • Hi Mark_A_Putt,

    Actually this forum is to discuss the VS IDE issue, if this issue is related to web, you could ask this question in the ASP.NET forum: http://forums.asp.net. If then, you could get an answer more quickly and professional. Thanks for your cooperation.

    Best Regards,

    Jack


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, December 5, 2014 7:16 AM