The model backing the --Context context has changed since the database was created - but db is new production database

0 votes

I am getting an error as soon as I attempt to access my Production site, straight after deleting the 'production' database on Azure and then publishing my site.

The model backing the 'PropertyContext' context has changed since the database was created. Consider using Code First Migrations to update the database

I deleted the database because I couldn't fix this issue any other way but it still doesn't work.

Some important points:

  • I'm using EF6 and publishing to Azure.
  • This is 1 of 2 projects/sites that uses the same Repo project. I have no
    problems with the other one, just this one.
  • I have tried publishing the problem project first (after deleting the db) and second with the same result.
  • I have tried deleting both WEBSITES and the DB from Azure and starting again
  • I have tried deleting all migrations and starting with a fresh data model
  • I have tried the following in my Global.asax (in both projects)

    Database.SetInitializer PropertyContext>(null); <-- SO won't let me put the first <

and

Database.SetInitializer(new MigrateDatabaseToLatestVersion<PropertyContext, MyConfiguration>());
new PropertyContext().Database.Initialize(true);

FYI: I'm using .net 4.5

Why am I getting this error on a new database and how can I get this site to work?

Jun 26, 2018 in Azure by null_void
• 3,220 points
2,263 views

1 answer to this question.

0 votes

Hey, I came across the same error in ASP.Net application. In my case I did not use Code First, but I used standard ASP.Net authentication provider which apparently uses Code First, and authentication was broken because of this issue.

Here is quick and dirty solution is you don't care much about existing user records:​

For me the solution was to drop the dbo.__MigrationHistory table, authentication started working fine after that. Be aware! This solution is not for everyone! This will fix the problem, but it is potentially risky.

If you cannot afford to lose data in AspNet* tables:​

ASP.Net authentication provider automatically creates tables in your database:

  • AspNetRoles
  • AspNetUsers
  • AspNetUserRoles
  • AspNetUserClaims
  • AspNetUserLogings

The tables are empty by default, if you haven't created any new logins for your web site, you can use "quick and dirty" solution above. If you do care about preserving user information or just curios how Code First migrations work, follow these steps:

  • Open your Web.config file and check the name of the connection string you have for your database. It will be one of the records under <connectionStrings> element.
  • Open Package Manager Console:

    Tools –> Library Package Manager –> Package Manager Console

  • In Package Manager Console window, use a drop-down to set Default Project. Make sure this is the project that contains ASP.Net authentication provider code.
  • Execute command:
    Update-Database -ConnectionStringName MyConnectionStringName

Replace the MyConnectionStringName with the actual name you looked up in web.config.

As a result of this command you will see a new folder "Migrations" with a bunch of code generated by the Update-Database command. Re-build and re-deploy your app, your new migration code will be executed on startup and would bring the database schema in sync with an updated version of ASP.Net authentication provider code.

answered Jun 26, 2018 by club_seesharp
• 3,450 points

Related Questions In Azure

0 votes
1 answer

Where is the storage account name and access keys on the portal?

In the image under the connection string ...READ MORE

answered May 22, 2018 in Azure by null_void
• 3,220 points
680 views
0 votes
1 answer

Error: Install-Module : The term 'Install-Module' is not recognized as the name of a cmdlet

Since you are using the lower version ...READ MORE

answered Jun 20, 2018 in Azure by null_void
• 3,220 points
3,961 views
0 votes
1 answer

What is the best "Web API Authentication" practice?

Talking about the best practice, consider the ...READ MORE

answered Aug 7, 2018 in Azure by null_void
• 3,220 points
945 views
0 votes
1 answer

Error: The subscription is not registered to use namespace 'Microsoft.DataFactory

In Azure, for each functionality there's a ...READ MORE

answered Aug 24, 2018 in Azure by null_void
• 3,220 points
1,612 views
0 votes
1 answer

Azure has 3 different types of storage accounts. Is there any major difference between them?

Azure Storage provides three types of storage ...READ MORE

answered Mar 4, 2019 in Azure by Prerna
• 1,960 points
26,879 views
0 votes
1 answer

How to calculate the used database space in SQL Azure?

I don't think its possible to find ...READ MORE

answered Mar 5, 2019 in Azure by Archana
• 5,640 points
1,268 views
0 votes
1 answer

How to add a body to a HttpWebRequest that is being used with the Azure Service management API?

The following code should help: byte[] buf = ...READ MORE

answered Apr 3, 2019 in Azure by Prerna
• 1,960 points
2,715 views
0 votes
0 answers

What is the use of cloud service configuration file (.cscfg) in azure?

What is the use of cloud service ...READ MORE

Sep 30, 2019 in Azure by Pratibha
• 3,690 points
1,186 views
0 votes
1 answer

Cannot delete blob: There is currently a lease on the blob and no lease ID was specified in the request

Alternatively, you can just kill the lease ...READ MORE

answered Sep 24, 2018 in Azure by club_seesharp
• 3,450 points
3,292 views
0 votes
1 answer

The user or administrator has not consented to use the application-Send interactive authorization request

An admin must consent to the permissions. ...READ MORE

answered Aug 24, 2018 in Azure by club_seesharp
• 3,450 points
8,564 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP