[英]Sql-Alchemy; ForeignKey Error
My problem comes down to the following code: 我的问题归结为以下代码:
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)
(It's the wrapped sql-alchemy from flask but I'm pretty sure this does not matter for this problem.) (这是来自flask的包装的sql-alchemy,但是我很确定这对这个问题无关紧要。)
The above gives me: 上面给了我:
sqlalchemy.exc.OperationalError: (OperationalError) (1005, "Can't create table 'crowdtracker.task_one_included_object' (errno: 150)")
I can not undertand why I'm getting this error. 我不明白为什么我会收到此错误。 When I remove the timestampStart
Column the queries run through. 当我删除timestampStart
列时,查询将通过。 I also added autoincrement=False
to the foreign key without success. 我还autoincrement=False
键添加了autoincrement=False
,但没有成功。
Best regards 最好的祝福
I solved it now by defining the composite foreign key via ForeignKeyConstraint()
which seems to support composite foreign keys. 我现在通过似乎支持复合外键的ForeignKeyConstraint()
定义了复合外键来解决了这个问题。 ( http://docs.sqlalchemy.org/en/rel_0_9/core/constraints.html#defining-foreign-keys ) ( http://docs.sqlalchemy.org/en/rel_0_9/core/constraints.html#defining-foreign-keys )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.