Reputation: 325
I am learning through the MVC4 default project files.
I am trying to add a new column into the default UserProfile table but it doesn't work for me. The column is added on the editor but I can only save the table as another .sql script extension file.
Therefore I follow this article
and added a property
public string UserEmail(){get;set;}
into the UserProfile class
Then I rerun "update-database -verbose"
But I get the error
There is already an object named 'UserProfile' in the database.
Upvotes: 2
Views: 233
Reputation: 3764
With Entity Framework 5 and Database Migration, every time you add a property to the model in your case Model being UserProfile
and you added public string UserEmail(){ get; set; }
you have to excute Update-Database -Force
in Package Manager Console to update your database or you will get that error you mentioned above. Also make sure that the right project is sellected while you do this. And while you are at it, in your Configuaration.cs
set AutomaticMigrationsEnabled = true;
This is good during development but set it to false once you are about to deploy to production.
Upvotes: 1
Reputation: 1762
I think in the Default Userprofile is still in AccountsModels.cs (in Models dir), and having 2 classes with the same name is not allowed. do a CTRL F for "class UserProfile", if you don t find 2 then try to add the -Force flag.
Upvotes: 0