title: How to add a NOT NULLABLE column with a foreign key to an existing table that already contains data?
body: <p>An example for this problem: </p>
  
  <blockquote>
    <p>Imagine you have a table projects. The table projects already 
    contains data. Now you want to add a project_type_id column to the 
    table, that can't be NULL and has a foreign key to the project_types 
    table. </p>
    
    <p>The database sees the project_type_id can't be NULL, so it inserts a 
    0 in the column for all the existing rows. The 0 does not exist in 
    the project_types table, so the foreign key constraint fails. This 
    means you can't add the foreign key.</p>
  </blockquote>
  
  <p>I thought about adding a first "default" row to the project_types table and link all the projects to that type. This isn't a good solution, because the user has to change all the types from "default" to the correct type.</p>
  
  <p>What is your solution for this problem?</p>