lundi 30 mars 2015

Create unique constraint with check in sqlalchemy


Vote count:

0




Prompt me please, how create unique constraint with check in sqlalchemy.


I've got table with unique field sku but I don't delete objects from db. I just mark it through field is_removed thus I can't create new object with same sku when object with same sku exist in db but already deleted(is_removed=True)


I want create unique constraint with check in sqlalchemy, but I don't know how.


Something like this:



class Model(db.Model):
#but only when is_removed == False. How do write this?
__table_args__ = (UniqueConstraint('is_removed', 'sku',),)
id = db.Column(db.Integer, primary_key=True)
sku = db.Column(db.String(100), nullable=False)
is_removed = db.Column(db.Boolean, default=False)


asked 33 secs ago







Create unique constraint with check in sqlalchemy

Aucun commentaire:

Enregistrer un commentaire