title: Entity Framework Migrations - Change Property DataType
body: <p>I am developing an ASP.Net MVC 4 web application with Entity Framework 5.0 for data persistence. I am using Code First and Automatic Migrations during development. </p>
  
  <p>As I had to work with an existing database I used this helpful tutorial to create my Domain Classes<br>
  <a href="http://msdn.microsoft.com/en-gb/data/jj200620" rel="nofollow">Code First to an Existing Database</a></p>
  
  <p>I have a class in my model named <strong>tblcourseapplicant</strong> which has a String property called <strong>ManagerTitle</strong>. I would like to change this datatype to <strong>Int</strong>, and to do this I changed the property in the POCO class </p>
  
  <p>from </p>
  
  <pre><code>public string ManagerTitle { get; set; }
  </code></pre>
  
  <p>to</p>
  
  <pre><code>public int ManagerTitle { get; set; }
  </code></pre>
  
  <p>and then I changed the property attribute in the relevant Mapping Class (tblcourseapplicantMap) using Fluent API</p>
  
  <p>from</p>
  
  <pre><code>this.Property(t =&gt; t.ManagerTitle).HasMaxLength(5);
  </code></pre>
  
  <p>to</p>
  
  <pre><code>this.Property(t =&gt; t.ManagerTitle).IsRequired();
  </code></pre>
  
  <p>I also updated all the data in the database for this particular column so that all the values were converted to integers. </p>
  
  <p>I ran my project and the automatic migrations try to perform this update for me, but it comes back with the following error</p>
  
  <blockquote>
    <p>Cannot insert the value NULL into column 'ManagerTitle', table
    'tblcourseapplicant'; column does not allow nulls. UPDATE fails. The
    statement has been terminated.</p>
  </blockquote>
  
  <p>I can't understand why this is, as there are no records in my database table where ManagerTitle is NULL, they have all been assigned an integer value.</p>
  
  <p>Any help would be greatly appreciated.</p>
  
  <p>Thanks.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Folks I am still struggling to find a solution to this problem. I noticed that the error coming back is an <strong>SqlException</strong>. Does anyone have any ideas please? I don't understand what the problem is here, my understanding is that Code First Automatic Migrations should be able to handle this simple property datatype change.</p>
  
  <p>Help!</p>