title: Flask - (sqlite3.IntegrityError) NOT NULL constraint failed even after migration
body: <p>I have created a one-to-many database relationship between the following:</p>
  
  <p>models.py</p>
  
  <pre><code>class User(db.Model, UserMixin):
      __tablename__ = "user"
  
      id = db.Column(db.Integer, primary_key=True, autoincrement=True)
      username = db.Column(db.String(20), unique=True, nullable=False)
      email = db.Column(db.String(120), unique=True, nullable=False)
      password = db.Column(db.String(60), nullable=False)
  
      histories = db.relationship('History', backref='admin', lazy=True)
  
      def save(self):
          db.session.add(self)
          db.session.commit()
  
      def __repr__(self):
          return f"User('{self.id}', '{self.username}', '{self.email})"
  
  
  class History(db.Model):
      __tablename__ = "history"
  
      id = db.Column(db.Integer, primary_key=True, autoincrement=True)
      date_posted = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
      offender_ip = db.Column(db.String(100), nullable=False)
      offender_mac = db.Column(db.String(100), nullable=False)
      action = db.Column(db.String(100), nullable=False)
      classification = db.Column(db.String(100), nullable=False)
      case_id = db.Column(db.String(100), nullable=False)
  
      user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
  
      def save(self):
          db.session.add(self)
          db.session.commit()
  
      def __repr__(self):
          return f"Post('{self.id}', {self.date_posted}', '{self.offender_ip}', '{self.offender_mac}', '{self.action}'," \
              f" '{self.classification}', '{self.case_id}')"
  </code></pre>
  
  <p><br>
  I get the error when creating an instance of 'History' here:</p>
  
  <pre><code>@app.route("/block/add/result", methods=['GET', "POST"])
  def block_submit_add():
      print(current_user)
      get_user = "user"
      get_password = "password"
  
      get_mac = request.form["mac"]
      get_offender_ip = request.form["off_ip"]
      get_classification = request.form["classification"]
      get_case_id = request.form["case_id"]
      now = datetime.now()
  
      if current_user.is_authenticated:
          history = History(date_posted=now, offender_ip=get_offender_ip,
                            offender_mac=get_mac, action="BLOCKED", classification=get_classification, case_id=get_case_id)
          db.session.add(history)
          db.session.commit()
  
          user = History.query.filter_by(offender_mac=get_mac).first()
  
          print(user.offender_ip)
          print(user.classification)
          print(user.get_case_id)
  </code></pre>
  
  <p><br>
  I also have a 'load_user' function that uses 'user_loader' from Flask-Login:</p>
  
  <pre><code>@login_manager.user_loader
  def load_user(user_id):
      return User.query.get(int(user_id))
  </code></pre>
  
  <p><br>
  Here is the full error:</p>
  
  <pre><code>sqlalchemy.exc.IntegrityError: (sqlite3.IntegrityError) NOT NULL constraint failed: history.user_id
  [SQL: INSERT INTO history (date_posted, offender_ip, offender_mac, action, classification, case_id, user_id) VALUES (?, ?, ?, ?, ?, ?, ?)]
  [parameters: ('2019-08-01 23:35:01.351985', '10.0.0.0', '00:00:00:00:00:00', 'BLOCKED', 'Test', '123', None)]
  </code></pre>
  
  <p><br><br>
  Is there a reason why 'History.user_id' is None? I have also tried to do a database migration/upgrade with Alembic and still receive the error.</p>