- changed status to invalid
Incorrect Postgres sequences
Issue #1563
resolved
SQLAlchemy must be attach sequence to field
Example:
>>> __import__('sqlalchemy').__version__
'0.5.6'
>>> from sqlalchemy import create_engine, MetaData, Table, Column, Integer, Sequence
>>> engine = create_engine('postgres://test@localhost/test', echo=True)
>>> metadata = MetaData()
>>> temp_table = Table('temp', metadata,
... Column('id', Integer,Sequence('test_id_seq'), primary_key=True)
... )
>>> metadata.create_all(engine)
...
2009-10-06 17:49:09,257 INFO sqlalchemy.engine.base.Engine.0x...b22c CREATE SEQUENCE test_id_seq
...
CREATE TABLE temp (
id INTEGER NOT NULL,
PRIMARY KEY (id)
)
...
Table SQL must be
CREATE TABLE temp (
id SERIAL,
PRIMARY KEY (id)
)
or
CREATE SEQUENCE test_id_seq;
CREATE TABLE temp (
id integer DEFAULT nextval('test_id_seq') NOT NULL,
PRIMARY KEY (id)
);
Comments (2)
-
repo owner -
repo owner - removed milestone
Removing milestone: 0.5.7 (automated comment)
- Log in to comment
dont use
Sequence()
- the SERIAL datatype will be used instead. If you'd likeSequence()
to be present such that the table works on Oracle/Firebird as well, addoptional=True
to theSequence
. Documented here: http://www.sqlalchemy.org/docs/05/metadata.html#defining-sequencesAlternatively you can specify
server_default=text("nextval('test_id_seq')")
to get the exact DEFAULT clause you're looking for there but the automatic approach is easier.