Last post Feb 27, 2017 08:47 AM by AngelinaJolie
Feb 21, 2017 11:01 AM|Bradly|LINK
In my production test database all contents is lost.
I published to a local directory on my development machine, then i transferred the files by ftp to the production test machine.
I wanted to make SQL changes to the database manually.
I tried to login the website, but that did not work, i checked the database , and it was empty .
What hapend here ? Any ideas ?
Best regards, Bradly
Feb 21, 2017 12:14 PM|PatriceSc|LINK
Which db are you using? Looks like you are using a file based database (or SQL Server with AttachDbFilename) and that you have overwritten this file.
Feb 21, 2017 02:10 PM|Bradly|LINK
ow yeah good one, we use MS-SQL server 2012.
No db files are overwritten, probably something EF does.
Feb 21, 2017 02:27 PM|PatriceSc|LINK
Could it be that you are using a DropCreateDatabaseAlways initializer ?
Feb 22, 2017 09:58 AM|Bradly|LINK
i found this one : public class ApplicationDbInitializer : DropCreateDatabaseIfModelChanges<ApplicationDbContext>
i am using the vs asp.mvc template, apparently this also happens in production / release.
Feb 22, 2017 11:57 AM|PatriceSc|LINK
So it likely found a schema change and dropped the database to recreate it. Try perhaps to select the create_date from the sys.databases view to see when your db were created. You could also have a look at the creation date for objects found in your db to
confirm the issue is really that the db has been created again from scratch.
At this point, it's likely you have no choice than to restore you db (hopefully you had a proper backup/restore strategy), disable this inializer and compare the schema with a reference to spot schema changes and perhaps apply them manually.
If I remember the strategy for EF7 is to do that "offline" (and maybe include that in your app but you have to be really explicit). IMO this is a good thing. I started before EF and never really liked handling schema changes as part of the app (I'm not even
using EF migrations).
Feb 23, 2017 11:01 AM|Bradly|LINK
the initializer is removed now , but i get the following message
The model backing the 'ApplicationDbContext' context has changed since the database was created. Consider using Code First Migrations to update the database (http://go.microsoft.com/fwlink/?LinkId=238269).
In development i want to use code first migration, and in production i would like to make the changes manually , how can i disable this in production ?
Feb 27, 2017 08:47 AM|AngelinaJolie|LINK
Hi Bradly ,
Please check this article:
To solve this error writhe the following code in Application_Start() Method in Global.asax.cs file