title: Binary fields in code-first migrations
body: <p>Regards,</p>
  
  <p>I have problems with migrations and binary fields...</p>
  
  <p>My initial migration looks like this (I had an existing database):</p>
  
  <pre><code>public override void Up()
  {
      CreateTable("dbo.Words", c =&gt; new
      {
          ID = c.Int(nullable: false, identity: true),
          Name = c.String(maxLength: 4000),
          Image = c.Binary(),
          Audio = c.Binary(),
      }).PrimaryKey(t =&gt; t.ID);
  }
  </code></pre>
  
  <p>And the Entity class is here:</p>
  
  <pre><code>public class Word
  {
      public int ID { get; set; }
      public string Name { get; set; }
      [MaxLength]
      public byte[] Image { get; set; }
      [MaxLength]
      public byte[] Audio { get; set; }
  }
  </code></pre>
  
  <p>I have automatic migrations turned on.
  Now if I drop all the tables from the database and run "Update-Database" I get:</p>
  
  <pre><code>Applying code-based migration: 201304211813502_InitialMigration.
  Applying automatic migration: 201304212024538_AutomaticMigration.
  System.Data.SqlServerCe.SqlCeException (0x80004005): Cannot alter column of type NTEXT or IMAGE [ Column Name = Image ]
  </code></pre>
  
  <p>So it looks like something is not in sync.. I run "Add-Migration AutoMigration" to see what entity framework had in mind it has to still be updated... The file I get is here:</p>
  
  <pre><code>public partial class AutoMigration: DbMigration
  {
      public override void Up()
      {
          AlterColumn("dbo.Words", "Image", c =&gt; c.Binary());
          AlterColumn("dbo.Words", "Audio", c =&gt; c.Binary());
      }
  
      public override void Down()
      {
          AlterColumn("dbo.Words", "Audio", c =&gt; c.Binary(maxLength: 4000));
          AlterColumn("dbo.Words", "Image", c =&gt; c.Binary(maxLength: 4000));
      }
  }
  </code></pre>
  
  <p>So... from this it looks like EF thinks Image and Audio fields are Binary(maxLength: 4000).. but they're not supposed to be!! (because in the initial migration they are <strong>Binary()</strong>).</p>
  
  <p>So I'm stuck and cannot get up-to-date with my migrations... and I need MaxLength (unlimited) binary fields...</p>
  
  <p>What could be going on here?
  thank you!
  david</p>