title: How to handle unique data in SQLAlchemy, flask, pyhon
body: <p>How do you usually handle unique database entries in Flask? I have the following column in my db model:</p>
  
  <pre><code>bank_address = db.Column(db.String(42), unique=True)
  </code></pre>
  
  <p>The problem is, that even before I can make a check whether it is already in the database or not, I get an error: </p>
  
  <p>Check if it is unique and THEN write into db:</p>
  
  <pre><code>if request.method == 'POST':
      if user.bank_address != request.form['bank_address_field']:
          user.bank_address = request.form['bank_address_field']
          db.session.add(user)
          db.session.commit()
  </code></pre>
  
  <p>The error I get:</p>
  
  <blockquote>
    <p>sqlalchemy.exc.IntegrityError: (sqlite3.IntegrityError) UNIQUE
    constraint failed: user.bank_address_field [SQL: 'UPDATE user SET
    bank_address_field=? WHERE user.id = ?']</p>
  </blockquote>