Automatic Migrations for ASP.NET SimpleMembershipProvider

前端 未结 3 1999
猫巷女王i
猫巷女王i 2020-12-02 05:38

So I tried to use automatic migrations with my new MVC 4 Project but somehow it isn\'t working. I followed this blog post step by step.

I\'ve added the changes to th

相关标签:
3条回答
  • 2020-12-02 05:49

    What it looks like happened here is that you enabled migrations, then ran the application. By running the application before using the UpdateDatabase command, EntityFramework would have created and populated the database but since when you enabled migrations the database didn't exist, it didn't create the InitialCreate migration. Migrations still thinks that you have an empty database and wants to create all of the objects in your model

    What you can try is to either re-enable migrations which will generate an InitialCreate migration that reflects the current state of the database. In this case I would save the changes you made to the seed method than run "Enable-Migrations -Force", this should recreate the migration and generate an IntialCreate migration. You can then repopulate your seed method and run the UpdateDatabase command.

    0 讨论(0)
  • 2020-12-02 05:52

    I had same and sorted in different way. Went to my local db deleted the UserProfile and other tables having foreign key constraints webpages_Membership,webpages_OAuthMembership,webpages_Roles,webpages_UsersInRoles tables. All these will recreate when you run update-database -verbose.

    0 讨论(0)
  • 2020-12-02 06:06

    update-database -verbose doesn't work because your model has been changed after your data table already existed.

    First, make sure there are no changes to the UserProfile class. Then, run:

    Add-Migration InitialMigrations -IgnoreChanges

    This should generate a blank "InitialMigration" file. Now, add any desired changes to the UserProfile class. Once changes are added, run the update command again:

    update-database -verbose

    Now the automatic migration will be applied and the table will be altered with your changes.

    0 讨论(0)
提交回复
热议问题