invalid autoincrement setting can be reflected, causing failures

Issue #3835 resolved
Mike Bayer repo owner created an issue
from sqlalchemy import *

m = MetaData()
t = Table(
    't', m,
    Column(
        'x', Integer, primary_key=True)
)


e = create_engine("postgresql://scott:tiger@localhost/test", echo=True)
m.drop_all(e)
m.create_all(e)

e.execute("alter table t alter column x type varchar(50)")

m2 = MetaData()
t2 = Table('t', m2, autoload_with=e)

from sqlalchemy.schema import CreateTable

print CreateTable(t2)

output:

sqlalchemy.exc.ArgumentError: Column type VARCHAR(50) on column 't.x' is not compatible with autoincrement=True

Comments (4)

  1. Mike Bayer reporter

    related to downstream sqlalchemy_migrate test suite, which also needs its own fix in this area.

  2. Mike Bayer reporter

    Don't set pg autoincrement if type affinity is not Integer

    Postgresql table reflection will ensure that the :paramref:.Column.autoincrement flag is set to False when reflecting a primary key column that is not of an :class:.Integer datatype, even if the default is related to an integer-generating sequence. This can happen if a column is created as SERIAL and the datatype is changed. The autoincrement flag can only be True if the datatype is of integer affinity in the 1.1 series.

    This bug is related to a test failure in downstream sqlalchemy_migrate.

    Change-Id: I40260e47e1927a1ac940538408983c943bbdba28 Fixes: #3835

    → <<cset 232eec47d139>>

  3. Log in to comment