New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing column type drops autoincrement #413

Closed
sqlalchemy-bot opened this Issue Feb 17, 2017 · 8 comments

Comments

Projects
None yet
1 participant
@sqlalchemy-bot

sqlalchemy-bot commented Feb 17, 2017

Migrated issue, originally created by Corwin Tanner

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.

@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Feb 18, 2017

Michael Bayer (@zzzeek) wrote:

MySQL's ALTER COLUMN has to re-specify the column all over again. So you need to specify auto_increment. Did you try that?

@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Feb 18, 2017

Michael Bayer (@zzzeek) wrote:

oh, you're talking about autogenerate ? right.

@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Feb 18, 2017

Michael Bayer (@zzzeek) wrote:

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.

@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Feb 18, 2017

Changes by Michael Bayer (@zzzeek):

  • set milestone to "fasttrack"
@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Feb 21, 2017

Corwin Tanner wrote:

Sorry for the delayed reply. You are correct that I am talking about autogen.

@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Feb 22, 2017

Michael Bayer (@zzzeek) wrote:

https://gerrit.sqlalchemy.org/315 . This is not a full detection of "change" for autoincrement, as this is not generally available across backends. It's limited to just making sure the flag is set to True if we know that the column will require the AUTO_INCREMENT directive if being recreated.

@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Feb 22, 2017

Michael Bayer (@zzzeek) wrote:

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

f99eb38

@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Feb 22, 2017

Changes by Michael Bayer (@zzzeek):

  • changed status to closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment