One-to-one relationship in Flask

后端 未结 2 1656
别跟我提以往
别跟我提以往 2021-01-16 05:39

I\'m trying to create a one-to-one relationship in Flask using SqlAlchemy. I followed this previous post and I created the classes like ones below:

class Im         


        
2条回答
  •  無奈伤痛
    2021-01-16 06:10

    Try out this

    enter code here
    
    class Image(db.Model):
        __tablename__ = 'image'
        image_id = db.Column(db.Integer, primary_key = True)
        name = db.Column(db.String(8))
    
    class Blindmap(db.Model):
        __tablename__ = 'blindmap'
        module_id = db.Column(db.Integer, primary_key = True)
        image_id = db.Column(db.Integer, ForeignKey('image.image_id'),unique=True)
    

提交回复
热议问题