title: Flask - SQLAlchemy - Add nullable=False column to existing table with data
body: <p>I'm trying to add a new <code>nullable=False</code> column to an existing table. But it won't create the column because there are existing rows and the field is <code>Null</code>.</p>
  
  <p>It's a classic catch 22 :D.</p>
  
  <p>here's my model column I added:</p>
  
  <pre class="lang-py prettyprint-override"><code>user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
  </code></pre>
  
  <p>here's the error I get</p>
  
  <pre><code>sqlalchemy.exc.IntegrityError: (psycopg2.errors.NotNullViolation) column "user_id" contains null values
  </code></pre>
  
  <p>I tried adding <code>, default=0</code> to the end of the attribute in the model hoping the migration would just set all existing row's column values to <code>0</code>, but this didn't have any effect.</p>
  
  <p>I don't see any documentation around this seemingly common phenomenon so I thought I'd ask the experts. What am I missing?</p>