Entity Framework Code First Migration in MySql DataBase

c# entity-framework entity-framework-6 migration mysql

Question

I create code first model using entity framework and after install first version to client we found some change in columns of database , I use migration of Entity Framework and you apply all steps of migration bat the data base of client not exist rows of migration history of last change and show this message if execute

Table 'nameTable' already exists

or

Additional information: Duplicate column name 'Reference'

this code of class configuration

 internal sealed class Configuration : DbMigrationsConfiguration<GSM.DataAccess.GSMContext>
{
    public Configuration()
    {
        AutomaticMigrationsEnabled = true;
        AutomaticMigrationDataLossAllowed = false;
        SetSqlGenerator("MySql.Data.MySqlClient", new MySql.Data.Entity.MySqlMigrationSqlGenerator());  
    }

    protected override void Seed(GSM.DataAccess.GSMContext context)
    {

    }
}

and this code of class first migration

public partial class AddMoreInformationColumn : DbMigration
{
    public override void Up()
    {

            AddColumn("dbo.People", "Reference", c => c.String(unicode: false));
            AddColumn("dbo.Products", "Reference", c => c.String(unicode: false));
            AddColumn("dbo.Products", "SalePrice", c => c.String(unicode: false));
            AddColumn("dbo.Products", "WholePrice", c => c.String(unicode: false));


    }

    public override void Down()
    {

            DropColumn("dbo.People", "Address");
            DropColumn("dbo.People", "Reference");
            DropColumn("dbo.Products", "Reference");
            DropColumn("dbo.Products", "SalePrice");
            DropColumn("dbo.Products", "WholePrice");

    }
}
1
1
8/13/2015 8:51:36 AM

Accepted Answer

As to the current problem, it looks like the client migration snapshot is out of sync. You could just comment out the conflicting code in the Up() method and do an update-database to get them back in sync. If you are concerned there are missing changes you will need to use a schema comparison tool (http://www.techbubbles.com/sql-server/schema-compare-for-sql-server-in-visual-studio-2013/).

I would rethink your strategy for updating the client (PRODUCTION) database(s). What we do is generate a script from our migrations that is run on the client site to update them. See: http://cpratt.co/migrating-production-database-with-entity-framework-code-first/#at_pco=smlwn-1.0&at_si=54ad5c7b61c48943&at_ab=per-12&at_pos=0&at_tot=1

You also have to consider what your database initializer is and set it to null or migratetolatestversion for deployment.

1
8/13/2015 4:45:44 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow