locked
empty database after ftp publish to production (entity framework). RRS feed

  • Question

  • User-1232255770 posted

    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

    Tuesday, February 21, 2017 11:01 AM

Answers

All replies

  • User753101303 posted

    Hi,

    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.

    Tuesday, February 21, 2017 12:14 PM
  • User-1232255770 posted

    ow yeah good one, we use MS-SQL server 2012.

    No db files are overwritten, probably something EF does.

    Tuesday, February 21, 2017 2:10 PM
  • User753101303 posted

    Could it be that you are using a DropCreateDatabaseAlways initializer ?

    Tuesday, February 21, 2017 2:27 PM
  • User-1232255770 posted

    i found this one :   public class ApplicationDbInitializer : DropCreateDatabaseIfModelChanges<ApplicationDbContext> 

    i am using the vs asp.mvc template, apparently this also happens in production / release.


    Wednesday, February 22, 2017 9:58 AM
  • User753101303 posted

    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).

     

    Wednesday, February 22, 2017 11:57 AM
  • User-1232255770 posted

    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 ?

    Thank you 

    Thursday, February 23, 2017 11:01 AM
  • User-832373396 posted

    Hi Bradly ,

    Please check this article:

    http://cybarlab.com/context-has-changed-since-the-database-was-created 

    Solution:

    To solve this error writhe the following code in Application_Start() Method in Global.asax.cs file

    Database.SetInitializer<CustomerDBContext>(null);

    Best regards,

    Jolie

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, February 27, 2017 8:47 AM