class History(db.Model):
__tablename__ = 'opt_version_build_history'
jobid = db.Column(db.Integer,primary_key=True,db.ForeignKey('opt_version_project_test.id'))
buildid = db.Column(db.Integer,primary_key=True)
env = db.Column(db.String(32)
builddate = db.Column(db.TIMESTAMP)
result = db.Column(db.String(32))
db.PrimaryKeyConstraint()
假如我要将jobid和buildid定义为复合主键,是这样两个后面都加上primary_key=True就行了吗?
另外,我怎样获得一个复合主键的对象呢?
是History.query.get(jobid,buildid)这样吗?
向get传入由复合主键组成的元组即可
History.query.get((jobid,buildid))