- changed status to resolved
ForeignKey reference can't be used multiple times at table creation
Issue #1238
resolved
The following code shows the problem:
from sqlalchemy import MetaData, Table, Column, Integer, ForeignKey
m = MetaData("sqlite:///foo")
s = Table("spam", m,
Column("id", Integer, primary_key=True))
f = ForeignKey("spam.id")
t = Table("eggs", m,
Column("s1", Integer, f),
Column("s2", Integer, f))
s.create()
t.create()
The foreign key will be missing for eggs.s1:
andre@pb:~/tmp$ sqlite3 foo
SQLite version 3.4.0
Enter ".help" for instructions
sqlite> .schema
CREATE TABLE eggs (
s1 INTEGER,
s2 INTEGER,
FOREIGN KEY(s2) REFERENCES spam (id)
);
CREATE TABLE spam (
id INTEGER NOT NULL,
PRIMARY KEY (id)
);
I tested sqlalchemy 0.4.8 and 0.5.0rc4 using sqlight and postgres.
Comments (1)
-
repo owner - Log in to comment
851a14aa1a0e7a734a6f810f0e6e5c39d8e63b1b "fixes" the issue by raising an error message when this occurs. The ForeignKey object is stateful with regards to its parent and cannot be reused.