-1
我想在一對一的關係表中爲用戶製作一個配置文件。我如何爲用戶和用戶的個人資料做到這一點。SQL鍊金術一對一(瓶)
另外我想顯示將它們連接在一起..如何加入配置文件和用戶表CRUD操作。
太感謝你了..
class User(UserMixin, db.Model):
__tablename__ = 'users'
id = db.Column('user_id', db.Integer, primary_key = True)
email = db.Column(db.String(128), unique = True)
password = db.Column(db.String(200))
is_admin = db.Column(db.Boolean, default=False)
is_active = db.Column(db.Boolean, default = False)
token = db.Column(db.String(100), unique = True)
profile = relationship("Profile", lazy = "joined")
def __init__(self, email, password, token, is_admin = False, is_active = False):
self.email = email
self.password = self.GenerateHash(password)
self.is_active = is_active
self.is_admin = is_admin
self.token = token
類檔案
謝謝你的回答,back_populates在關係中有什麼含義? –
它用於讓知道sqlalchemy兩個表之間的連接,您可以通過使用'backref'來避免它。 [這個答案](https://stackoverflow.com/a/39870250)是一個很好的解釋。 –