none
How to get clean database accurate to my source files RRS feed

  • Question

  • I'm trying to get "clean" initial database.

    So if I delete development database and run unit test on code with Entity Framework database is created. Connection String for that database is stored in MigrationsContextFactory which derives after IDbContextFactory . This was all right for me until I have added one column to one of Table. After delete database and run test this columns won't show up in database table.

    If delete development database and run Update-Database i have got: Applying code-based migrations: [201302201810047_InitialCreate, 201302201840012_wieleDoWielu]. Applying code-based migration: 201302201810047_InitialCreate. Applying code-based migration: 201302201840012_wieleDoWielu.

    The problem is that now one of tables have only 3 columns. So it's less then after delete database and running unit test.

    After deleting Migration folder, running Enable-Migrations -EnableAutomaticMigrations -Force I have

    PM> Enable-Migrations -EnableAutomaticMigrations -Force
    Code First Migrations enabled for project 
    
    PM> Update-Database
    Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
    Applying code-based migrations: [201302201810047_InitialCreate, 201302201840012_wieleDoWielu].
    Applying code-based migration: 201302201810047_InitialCreate.
    Applying code-based migration: 201302201840012_wieleDoWielu.
    Unable to update database to match the current model because there are pending changes and automatic     migration is disabled. Either write the pending model changes to a code-based migration or enable automatic         migration. Set DbMigrationsConfiguration.AutomaticMigrationsEnabled to true to enable automatic migration.
    You can use the Add-Migration command to write the pending model changes to a code-based migration.

    So.. I still have table with less columns (3 only), only Configuration.cs in Migrations folder and MigrationId ProductVersion 201302201810047_InitialCreate 5.0.0.net45 201302201840012_wieleDoWielu 5.0.0.net45 in [dbo].[__MigrationHistory] datatable

    The question is. How project remember code-based migration: 201302201840012_wieleDoWielu? How can I delete it? How can I get "clean" database which is accurate to my code?

    Best Regards

    Przemysław Staniszewski

    Friday, February 22, 2013 1:17 PM

All replies

  • There is one more combination:

    After delete development database and run unit test i Have got database with

    MigrationId ProductVersion
    201302191330080_InitialCreate 5.0.0.net45 

    after runing

    PM> Update-Database
    Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
    Applying code-based migrations: [201302201840012_wieleDoWielu].
    Applying code-based migration: 201302201840012_wieleDoWielu.

    which can't be done.

    I wan't remove 201302201840012_wieleDoWielu . But where is this stored? I have delete Migrations folder eariel.

     

    Friday, February 22, 2013 1:34 PM
  • Hi Przemysław,

    Welcome to the MSDN forum.

    I am trying to involve a senior expert into your thread. Please wait for the response. Sorry for any inconvenience.

    Best Regards,


    Alexander Sun [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, February 25, 2013 8:17 AM
  • Hi

    I think the problem was that, if every time I started unit test this one runs with compiled library which has Migration files. So update from project where was no those files takes migration info from database.

    I really don't know. At fist computer run at Monday  everything just works fine.

    Tuesday, February 26, 2013 3:19 PM