Skip to content

Instantly share code, notes, and snippets.

@asyd
Created May 14, 2018 16:21
Show Gist options
  • Save asyd/3cff61ed09eabe187d3fbec2c8a3ee39 to your computer and use it in GitHub Desktop.
Save asyd/3cff61ed09eabe187d3fbec2c8a3ee39 to your computer and use it in GitHub Desktop.
Flask SQLAlchemy multiple column unique constraint
class ComponentCommit(db.Model):
__tablename__ = 'component_version'
__table_args__ = (
db.UniqueConstraint('component_id', 'commit_id', name='unique_component_commit'),
)
id = db.Column(db.Integer, primary_key=True)
component_id = db.Column(db.Integer, db.ForeignKey("component.id"))
commit_id = db.Column(db.String)
branch = db.Column(db.String)
dependencies = db.Column(db.Text)
created_date = db.Column(db.DateTime, default=datetime.datetime.utcnow)
updated_date = db.Column(db.DateTime)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment