Python Forum
Flask, When the associated foreign key is the same, it is a question of setting a uni
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Flask, When the associated foreign key is the same, it is a question of setting a uni
#1
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')
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Flask and SQLAlchemy question: Database is being created but tables aren't adding pythonpaul32 3 4,414 Feb-07-2023, 10:48 AM
Last Post: pythonpaul32
  Sqlalchemy foreign key problem IMuriel 2 7,105 Feb-07-2020, 06:19 AM
Last Post: praveen
Photo only foreign key id retrive when i pass model instance to form but i want other field x64 0 3,657 Jun-03-2017, 05:58 AM
Last Post: x64

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020