Python Forum

Full Version: Flask, When the associated foreign key is the same, it is a question of setting a uni
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
The flask, sqlalchemy is a question.

When business_idx is the same as foreign key,

In the same case, I would like to make the duplicate name uniquely unique.

I think this can be applied in sqlalchemy during the model setup phase. What should I do?

Thank you for giving us a simple example.


class Member(db.Model):
  __tablename__ = 'member'
  index = db.Column(db.Integer, unique=True, nullable=False, primary_key=True)
  business_idx = db.Column(db.Integer, db.ForeignKey('business.index'))
  name = db.Column(db.String(30), nullable=False)
  business = db.relationship('Business', back_populates='member')