我的问题归结为以下代码:
class TaskOneLine(db.Model):
userId = db.Column(db.String(64), primary_key=True)
timestampStart = db.Column(db.BIGINT, primary_key=True, autoincrement=False)
includedObjects = db.relationship("TaskOneIncludedObject")
class TaskOneIncludedObject(db.Model):
id = db.Column(db.BIGINT, primary_key=True)
#parent foreign key required for one-to-many-relation
userId = db.Column(db.String(64), db.ForeignKey('task_one_line.userId'))
timestampStart = db.Column(db.BIGINT, db.ForeignKey('task_one_line.timestampStart'), autoincrement=False)
(这是来自烧瓶的包装sql-alchemy,但我很确定这对于这个问题无关紧要。)
上面给了我:
sqlalchemy.exc.OperationalError: (OperationalError) (1005, "Can't create table 'crowdtracker.task_one_included_object' (errno: 150)")
我无法理解为什么我会收到此错误。当我删除timestampStart
列时,查询会一直运行。我还在外键中添加了autoincrement=False
但没有成功。
祝你好运
答案 0 :(得分:1)
我现在通过ForeignKeyConstraint()
定义复合外键来解决它,它似乎支持复合外键。 (http://docs.sqlalchemy.org/en/rel_0_9/core/constraints.html#defining-foreign-keys)