Changing column type drops autoincrement

Issue #413 resolved
Corwin Tanner
created an issue

If you alter the type of a column that has autoincrement=True, the resulting revision produces an alter_column operation without the autoincrement argument like so:

op.alter_column('table', 'column', existing_type=mysql.BIGINT(display_width=20, unsigned=True), type_=mysql.INTEGER(unsigned=True))

This produces an ALTER statement that removes the AUTO_INCREMENT property of the column.

Comments (6)

  1. Michael Bayer repo owner

    autoincrement is not present within the autogen mechanics or operation object's autogen related methods at all and would need to be implemented all the way through. might not be feasible prior to SQLA 1.1 either since autoincrement might not report a meaningful value in reflection, have to see.

  2. Michael Bayer repo owner

    Detect and render autoincrement for alter_column()

    The autoincrement=True flag is now rendered within the :meth:.Operations.alter_column operation if the source column indicates that this flag should be set to True. The behavior is sensitive to the SQLAlchemy version in place, as the "auto" default option is new in SQLAlchemy 1.1. When the source column indicates autoincrement as True or "auto", the flag will render as True if the original column contextually indicates that it should have "autoincrement" keywords, and when the source column explcitly sets it to False, this is also rendered. The behavior is intended to preserve the AUTO_INCREMENT flag on MySQL as the column is fully recreated on this backend. Note that this flag does not support alteration of a column's "autoincrement" status, as this is not portable across backends.

    Change-Id: I746c4841752adf9342bfdca7c9255aae5110b2ef Fixes: #413

    → <<cset f99eb38ceb20>>

  3. Log in to comment