[sqlalchemy] Sqlite with ForeignKey & sqlite_autoincrement syntax error

271 Aufrufe
Direkt zur ersten ungelesenen Nachricht

ratufa

ungelesen,
22.05.2010, 20:17:4922.05.10
an sqlalchemy
This is using SQLAlchemy version 0.6.0, Python 2.6.5.

The following program:

from sqlalchemy import Table, Column, Integer, String, MetaData
from sqlalchemy import ForeignKey, create_engine

metadata = MetaData()

table1 = Table('table1', metadata,
Column('id', Integer, primary_key = True),
Column('fid', Integer, ForeignKey('table2.id')),
sqlite_autoincrement = True)

table2 = Table('table2', metadata,
Column('id', Integer, primary_key = True),
Column('stuff', String), sqlite_autoincrement = True)

engine = create_engine('sqlite://', echo = True)

metadata.create_all(engine)

Generates the following commands:

CREATE TABLE table2 (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
stuff VARCHAR
)

CREATE TABLE table1 (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
fid INTEGER,
,
FOREIGN KEY(fid) REFERENCES table2 (id)
)

The extra comma in the Table1 creation causes a syntax error. This
seems to be a function of declaring a foreign key when also setting
sqlite_autoincrement = True. What am I doing wrong?

--
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To post to this group, send email to sqlal...@googlegroups.com.
To unsubscribe from this group, send email to sqlalchemy+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.

Michael Bayer

ungelesen,
22.05.2010, 23:56:3422.05.10
an sqlal...@googlegroups.com
thats a bug. seems like there would normally be a primary key constraint there which is being concealed due to the autoincrement keyword, yet the comma joining the (invisible) pk and fk constraints remains. ticket 1812.
Allen antworten
Antwort an Autor
Weiterleiten
0 neue Nachrichten