问题
I have searched all over the internet, stack overflow but i am feeling lost in the mystery of Entity framework Migration.
I have existing database. I have added three new tables which have some relation with AspNetUsers table.
I have tried two ways to add these tables to database using pmc. first comment out all new tables in dbcontext and then use following command.
Add-migration initial -ignorechanges
then uncomment the tables from dbcontext and run update-database command. result no new table added.
then i remove all the entries in migration history table and remove migration folder and start from scratch.
enable-migrations -EnableAutomaticMigrations
Add-migration bcvn
update-database -verbose
now, when i run update database, it says There is already an object named 'AspNetUsers' in the database.Found this article to be helpfull but in my case there are no changes going on AspNetUsers table in up method so i can follow this article http://blog.rajsoftware.com/2014/07/12/entity-framework-code-first-automatic-migration-existing-tables/ Please someone save me.May be i will receive many downvote .but i dont care i want solution.
回答1:
Got it working. The Trick was to comment out all the code related to new table especially the relationship related code which i was not doing before to ApplicationUser class then
Add-migration initial -ignorechanges
then uncomment all the code and then
update-database -verbose
The only thing which i was not doing before was to comment out the relationship like this--
// public virtual Notification Notifications { get; set; }
and in notification table
// public virtual ApplicationUser ApplicationUser { get; set; }
May be helpful for someone too.
来源:https://stackoverflow.com/questions/34606160/there-is-already-an-object-named-aspnetusers-in-the-database