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

autogenerate wrongly determined a primary key integer column to autoincrement #94

sqlalchemy-bot opened this Issue Dec 5, 2012 · 3 comments


None yet
1 participant

sqlalchemy-bot commented Dec 5, 2012

Migrated issue, originally created by Eric Hui (@ehui)

Hi, I use pyramid, added the following table in my models file

pageview_table = schema.Table('pageview', metadata,
  schema.Column('brand_id', types.Integer, schema.ForeignKey(''), nullable=False),
  schema.Column('platform', types.Integer, primary_key=True),
  schema.Column('object_type', types.Integer, primary_key=True),
  schema.Column('object_id', types.Integer, default=0, primary_key=True),
  schema.Column('viewcount', types.Integer, default=1, nullable=False),

ran --autogenerate and got following upgrade

def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    sa.Column('brand_id', sa.Integer(), nullable=False),
    sa.Column('platform', sa.Integer(), nullable=False),
    sa.Column('object_type', sa.Integer(), nullable=False),
    sa.Column('object_id', sa.Integer(), nullable=False),
    sa.Column('viewcount', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['brand_id'], [''], ),
    sa.PrimaryKeyConstraint('platform', 'object_type', 'object_id')
    ### end Alembic commands ###

when I checked it out in "offline" mode (upgrade head --sql), got the following

CREATE TABLE pageview (
    brand_id INTEGER NOT NULL, 
    object_type INTEGER NOT NULL, 
    object_id INTEGER NOT NULL, 
    viewcount INTEGER NOT NULL, 
    PRIMARY KEY (platform, object_type, object_id), 
    FOREIGN KEY(brand_id) REFERENCES brand (id)

I would like to be able to have the option to not AUTO_INCREMENT....

I was able to temporarily get around using the following in upgrade


works well except the default is 0 instead of NULL, am I misunderstanding something with server_default?

mysql> show columns from pageview;
| Field       | Type    | Null | Key | Default | Extra |
| brand_id    | int(11) | NO   | MUL | NULL    |       |
| platform    | int(11) | NO   | PRI | 0       |       |
| object_type | int(11) | NO   | PRI | NULL    |       |
| object_id   | int(11) | NO   | PRI | NULL    |       |
| viewcount   | int(11) | NO   |     | NULL    |       |



This comment has been minimized.

sqlalchemy-bot commented Dec 5, 2012

Changes by Eric Hui (@ehui):

  • edited description

This comment has been minimized.

sqlalchemy-bot commented Dec 5, 2012

Michael Bayer (@zzzeek) wrote:

just the "autoincrement=False" directive is enough for it to not say "AUTO_INCREMENT". Ideally, you'd want to put this in the "platform" Column definition inside the "pageview_table" Table you created in your pyramid app. There's a bug which I have just fixed in 97b7227 that would prevent this from being propagated to the migrate script. If you want to stay on 0.4.0, then add "autoincrement=False" to the column definition into your updgrade() script manually.


This comment has been minimized.

sqlalchemy-bot commented Dec 5, 2012

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