for postgresql, autoincrement=True means that if the column is marked
primary_key=True it will use the datatype SERIAL for that column, which
in PG does mean the sequence is generated and added as the server side
default.
Would you expect a SERIAL on Postgres to end up being an inteeger with a
default of a sequence when viewed in psql?
What happens with autoincrement on a non-primary-key column? My
experiences suggests it does nothing...
'ALTER TABLE some_table ADD COLUMN q SERIAL NOT NULL' does, indeed, add
a column of type 'integer' with a server-side default set to be the next
value from a sequence that is automagically created.
...but how can I specify I want a non-primary-key SERIAL column on a model?
that SO answer is showing op.create_table(). your example was just for
op.add_column(). super different.
I have to admit that, at the column level, that's surprising to me.
Where can I see the differences between a column created as part of
create_table() verus as part of an add_column()?
SQL wise the syntaxes are:
Okay, but from the docs:
https://www.postgresql.org/docs/9.1/static/sql-createtable.html
{ column_name data_type [ COLLATE collation ] [ column_constraint [ ... ] ]
https://www.postgresql.org/docs/9.1/static/sql-altertable.html
ADD [ COLUMN ] column data_type [ COLLATE collation ] [
column_constraint [ ... ] ]
...bar the initial verbage seem the same.
Alembic op.add_column() will emit the SERIAL if you send a Column with
primary_key=True and Integer datatype on a Postgresql backend. I just
added this to confirm:
+ def test_col_w_pk_is_serial(self):
+ context = op_fixture("postgresql")
+ op.add_column("some_table", Column('q', Integer,
primary_key=True))
+ context.assert_(
+ 'ALTER TABLE some_table ADD COLUMN q SERIAL NOT NULL'
+ )
SERIAL would be all you need here.
Cool, so back to my question above: how can I specify I want a
non-primary-key SERIAL column on a model? I hope I'm just being blind,
but I couldn't find SERIAL importable anywhere.
cheers,
Chris
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy-alembic" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to sqlalchemy-alembic+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.