title: EF5 Code First - Changing A Column Type With Migrations
body: <p>I am new to EF5 Code First and I'm tinkering with a proof-of-concept before embarking on a project at work.</p>
  
  <p>I have initially created a model that looked something like</p>
  
  <pre><code>public class Person {
    public int Id { get; set; }
    public string FirstName { get; set;}
    public string Surname {get;set;}
    public string Location {get;set;}
  }
  </code></pre>
  
  <p>And I added a few records using a little MVC application I stuck on the top.</p>
  
  <p>Now I want to change the Location column to an enum, something like:</p>
  
  <pre><code>public class Person {
    public int Id { get; set; }
    public string FirstName { get; set;}
    public string Surname {get;set;}
    public Locations Location {get;set;}
  }
  
  public enum Locations {
    London = 1,
    Edinburgh = 2,
    Cardiff = 3
  }
  </code></pre>
  
  <p>When I add the new migration I get:</p>
  
  <pre><code>AlterColumn("dbo.People", "Location", c =&gt; c.Int(nullable: false));
  </code></pre>
  
  <p>but when I run update-database I get an error</p>
  
  <pre><code>Conversion failed when converting the nvarchar value 'London' to data type int.
  </code></pre>
  
  <p>Is there a way in the migration to truncate the table before it runs the alter statement?</p>
  
  <p>I know I can open the database and manually do it, but is there a smarter way?</p>