How to deploy ASP.NET MVC site with existing database to Azure Web Apps?

不想你离开。 提交于 2019-12-06 07:18:09

According to the Stack Trace you provided, I assumed that you did not migrate the DB tables correctly. Based on the source code you linked, I could reproduce your issue after I deployed the website to Azure. Here is the DB tables on my Azure SQL.

Note: Upon the screenshot, we could see that there are only two properties in Users table.

After some trials, I could deploy my website to Azure successfully. You could follow the steps below and try to find whether it could work as expected on your side.

Modify the database initialization strategy below in Application_Start as you mentioned:

System.Data.Entity.Database.SetInitializer(new System.Data.Entity.MigrateDatabaseToLatestVersion<AuctionDataContext, Configuration>());

Move the initialization in function SetSecurityOptions to the bottom of the Seed() function within the Configuration class.

Note: Since you have enabled migrations, you need to either add the pending model changes to a code-based migration or enable automatic migration to update the database. So, you need to set DbMigrationsConfiguration.AutomaticMigrationsEnabled to true to enable automatic migration.

Result: http://bruce-chen-001.azurewebsites.net/

Additionally, please follow the tutorial provided by Russell Young for a better understanding of Code First Migrations.

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