The following EventInvitation
model is a simple invitation for one event, sent from a user to another user. I would like to ensure that the invitations are uniq
You need to add the constraint to the table, not the model. To do this using declarative:
class EventInvitation(db.Model):
# ...
__table_args__ = (
db.UniqueConstraint(event_id, from_id, to_id),
)
If the table has already been created in the database, you'll need to drop the table and run db.create_all()
again, or use Alembic to alter the existing table with a migration.