Entity Framework Code First Migration in MySql DataBase

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

Question

I use Entity Framework to generate the initial model of the code, and after installing the client's first version, we noticed certain changes to the database's columns. I then use Entity Framework to migrate the model, but when you complete the migration process, the client's data base does not exist. rows of migration history for the most recent modification, and if executed, this message

Table 'nameTable' already exists

or

Additional information: Duplicate column name 'Reference'

this class configuration code

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

    }
}

additionally, this class first migration code

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

It appears that the client migration snapshot is out of sync, which is the present issue. To get them back in sync, you could simply remove the conflicting code from the Up() method and update the database. You must utilize a schema comparison tool if you are concerned about missing modifications (http://www.techbubbles.com/sql-server/schema-compare-for-sql-server-in-visual-studio-2013/).

I would reconsider your plan for updating the production (client) database (s). To update the client site, we create a script from our migrations and run it there. Watch: zzz-13 zzz

You must also take into account the database initializer and set it to migratetolatestversion or null 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