Automatic Migrations for ASP.NET SimpleMembershipProvider

点点圈 提交于 2019-11-27 10:14:48
Haminh Nguyen

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.

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!