📜  db.relationship sqlalchemy 烧瓶 - SQL 代码示例

📅  最后修改于: 2022-03-11 15:04:53.350000             🧑  作者: Mango

代码示例1
class Person(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50), nullable=False)
    addresses = db.relationship('Address', backref='person', lazy=True)

class Address(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    email = db.Column(db.String(120), nullable=False)
    person_id = db.Column(db.Integer, db.ForeignKey('person.id'),
        nullable=False)