On Jan 28, 2011, at 8:07 AM, slothy Rulez a lot wrote: > Hi, [] > > I'm trying to create tables in SQLITE, with a composite PK (id, eid), I want > the id have the auto increment. > I've read this, > http://www.sqlalchemy.org/docs/dialects/sqlite.html#auto-incrementing-behavior, > and following your instructions, added __table_args__ = > {'sqlite_autoincrement':True} > (I'm using declarative), but i'm not having any difference. > > This is the debug exit and the declarative code: > > 2011-01-28 13:48:56,999 INFO sqlalchemy.engine.base.Engine.0x...b9ec > CREATE TABLE elementos_filiales ( > id INTEGER, > tipo TEXT, > timestamp TEXT, > eid VARCHAR(127) NOT NULL, > nombre TEXT, > eliminado INTEGER, > padre INTEGER, > PRIMARY KEY (id, eid), > FOREIGN KEY(padre) REFERENCES elementos_multinacionales (id) > )
What you are trying to do won't work in SQLite because INTEGER PRIMARY KEY is an alias for a special SQLite ROWID. So, when you create a two-column primary key, you lose the ROWID alias feature. AUTOINCREMENT can apparently only be used with a single-column primary key: sqlite> create table gonk(a INTEGER AUTOINCREMENT,b varchar,primary key(a,b)); Error: near "AUTOINCREMENT": syntax error sqlite> create table gonk(a INTEGER PRIMARY KEY AUTOINCREMENT,b varchar,primary key(a,b)); Error: table "gonk" has more than one primary key However, you should be able to create a table having id as the primary key and a unique constraint on (id,eid) which should be effectively the same. Cheers, M -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.