Responsive Ad Area

Share This Post

test

Add-Migration generates different migrations in VS2017 vs. VS2015

We recently moved from VS2015 to VS2017 for our EF Code First application. Some of the developers on the team (but not all) get different results calling Add-Migration on VS2015 and VS2017.

For instance, if I generate a migration on VS2015 with no outstanding model changes and a fresh build I get the expected empty migration

Add-Migration ... -Name ShouldBeAnEmptyMigration

gives me:

namespace Blah.Foo.DataModel.Migrations
{
    using System;
    using System.Data.Entity.Migrations;

    public partial class ShouldBeAnEmptyMigration: DbMigration
    {
        public override void Up()
        {
        }

        public override void Down()
        {
        }
    }
}

If I roll those changes back and run the same command against the same database from VS2017 I get a migration full of unwanted changes:

namespace Blah.Foo.DataModel.Migrations
{
    using System;
    using System.Data.Entity.Migrations;

    public partial class ShouldBeAnEmptyMigration: DbMigration
    {
        public override void Up()
        {
            // For some reason EF is trying to add foreign key columns that
            // already exist except with an additional suffix of "1".
            // e.g. We already have an FK from 'Child' to 'Parent' using
            // Guid Parent_Id which has been in place for (literally) years.
            // There are 11 such columns it is trying to add here.
            // Some date base a couple years, some are more recent.
            // I don't see a pattern for which columns it is choosing

            // 11 of these, one for each "new" column ...
            DropForeignKey("Child", "Parent_Id", "Parent");
            ...
            // 11 of these ...
            DropIndex("Child", new[] { "Parent_Id" });
            ...
            // 11 of these ...
            AddColumn("Child", "Parent_Id1", c => c.Guid(nullable: false));
            ...
            // 11 of these ...
            CreateIndex("Child", "Parent_Id1");
            ...
            // 11 of these ...
            AddForeignKey("Child", "Parent_Id1", "Parent", "Id");
            ...
        }

        public override void Down()
        {
            // similar set of DropForeignKey, DropIndex, DropColumn,
            // CreateIndex, AddForeignKey
        }
    }
}

Note that there are no recent changes to most of the DataModels affected.

Currently I am forced to create all my migrations on VS2015. Is there any way to make VS2017 “behave”?

Versions:

  • Visual Studio Pro 2015 (14.0.25431.01 Update 3)
  • Visual Studio Pro 2017 (15.9.7)
  • EntityFramework.6.2.0

Add-Migration generates different migrations in VS2017 vs. VS2015
Add-Migration generates different migrations in VS2017 vs. VS2015
test
{$excerpt:n}

Share This Post

Leave a Reply

Your email address will not be Publishedd. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Skip to toolbar