.. changelog::
:version: 1.1.3
+ .. change::
+ :tags: bug, postgresql
+ :tickets: 3835
+
+ 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.
+
.. change::
:tags: bug, sql
:tickets: 3833
if default is not None:
match = re.search(r"""(nextval\(')([^']+)('.*$)""", default)
if match is not None:
- autoincrement = True
+ if issubclass(coltype._type_affinity, sqltypes.Integer):
+ autoincrement = True
# the default is related to a Sequence
sch = schema
if '.' not in match.group(2) and sch is not None:
r = t3.insert().execute()
eq_(r.inserted_primary_key, [2])
+ @testing.provide_metadata
+ def test_altered_type_autoincrement_pk_reflection(self):
+ metadata = self.metadata
+ t = Table(
+ 't', metadata,
+ Column('id', Integer, primary_key=True),
+ Column('x', Integer)
+ )
+ metadata.create_all()
+ testing.db.connect().execution_options(autocommit=True).\
+ execute('alter table t alter column id type varchar(50)')
+ m2 = MetaData(testing.db)
+ t2 = Table('t', m2, autoload=True)
+ eq_(t2.c.id.autoincrement, False)
+ eq_(t2.c.x.autoincrement, False)
+
@testing.provide_metadata
def test_renamed_pk_reflection(self):
metadata = self.metadata