SQLAlchemy many-to-many relationship updating association object with extra column
You get an integrity error because you are trying to create a new object with the same primary keys.
This:
a = Set_Product_Association(set=s, product=p, quantity=43)
Does not update, but create.
If you want to update the actual row in the table, you need to update the existing one:
assoc = Set_Product_Association.query.filter_by(set=s, product=p).first()assoc.quantity = 43db.session.commit()
Also, from the documentation it is advised to not use a model but an actual table.