title: Entity Framework Migrations custom SQL not working
body: <p>Why does this not work?</p>
  
  <pre><code>AddColumn("dbo.Bins", "Code", c =&gt; c.String());
  //custom copy data from old BinCode column
  Sql("UPDATE Bins SET Code = BinCode WHERE BinCode IS NOT NULL");
  DropColumn("dbo.Bins", "BinCode");
  </code></pre>
  
  <p>Bins has Bin.BinCode with values set, when I run this inside of <code>DbMigration</code> I find that Bin.Code is <code>NULL</code>. </p>
  
  <p>EDIT:
  I don't actually run Update-Database in the package manager console, but I execute from my unit of work source:</p>
  
  <pre><code>        Database.SetInitializer&lt;eVendContext&gt;(new MigrateDatabaseToLatestVersion&lt;eVendContext, Configuration&gt;());
  </code></pre>
  
  <p>Edit 2:
  Just to clarify, The database <em>is</em> successfully updating to the latest migration. Simple the data is not copied across from BinCode field to Code field when complete.</p>
  
  <p>Edit 3:
  Here's the relevant output from Update-database -verbose:</p>
  
  <pre><code>ALTER TABLE [dbo].[Bins] ADD [Code] [nvarchar](max)
  UPDATE Bins SET Bins.Code = BinCode WHERE BinCode IS NOT NULL
  DECLARE @var0 nvarchar(128)
  SELECT @var0 = name
  FROM sys.default_constraints
  WHERE parent_object_id = object_id(N'dbo.Bins')
  AND col_name(parent_object_id, parent_column_id) = 'BinCode';
  IF @var0 IS NOT NULL
      EXECUTE('ALTER TABLE [dbo].[Bins] DROP CONSTRAINT [' + @var0 + ']')
  ALTER TABLE [dbo].[Bins] DROP COLUMN [BinCode]
  </code></pre>
  
  <p>When I run this output from verbose on my database as a complete script, I get an error "Invalid column name 'Code'". But each statement in turn updates my database as I would expect.</p>
  
  <p>Does this mean I need to perform this style of data transposition over multiple migrations or is there a way to let the migration know it has to perform each step in the migration separately?</p>