[sqlalchemy] Sqlite with ForeignKey & sqlite_autoincrement syntax error

269 views
Skip to first unread message

ratufa

unread,
May 22, 2010, 8:17:49 PM5/22/10
to 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

unread,
May 22, 2010, 11:56:34 PM5/22/10
to 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.
Reply all
Reply to author
Forward
0 new messages