我试图实现一个简单的sqlalchemy表关系
所以,我有以下型号:
class User(db.Model):
__tablename__ = "users"
UserID = db.Column(db.Integer, primary_key=True, autoincrement=True)
FirstName = db.Column(db.String(255), nullable=False)
LastName = db.Column(db.String(255), nullable=False)
#others column
Tokens = db.relationship('Token', backref='Token.UserID', primaryjoin='User.UserID==Token.UserID', lazy='dynamic')
#bla... other codes
和
class Token(db.Model):
__tablename__ = "user_tokens"
TokenID = db.Column(db.Integer, primary_key=True, autoincrement=True)
UserID = db.Column(db.Integer, db.ForeignKey('users.UserID'))
Token = db.Column(db.String(255), nullable=False)
#others column
#bla... other codes
我确实在询问:
user = User.query.filter(User.UserID).first()
问题:当我试图访问时:
print(user.Tokens.UserID)
# or
print(user.Tokens.Token)
我总是收到:
' AppenderBaseQuery'对象没有属性' UserID' /'令牌'
我在这里缺少什么?