Skip to content
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

drop_constraint etc. should check for name=None and emit informative error message since this is common w/ autogenerate #588

Open
torston opened this issue Jul 19, 2019 · 2 comments
Labels
missing behavior not quite a feature and not quite a bug, somehting we need to support naming convention issues op directives

Comments

@torston
Copy link

torston commented Jul 19, 2019

I made migration with alembic revision --autogenerate which contains addition of foreign key:

def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('image_resource',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('url', sa.String(length=250), nullable=False),
    sa.PrimaryKeyConstraint('id')
    )
    op.add_column('category', sa.Column('image_id', sa.Integer(), nullable=True))
    op.create_foreign_key(None, 'category', 'image_resource', ['image_id'], ['id'])
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint(None, 'category', type_='foreignkey')
    op.drop_column('category', 'image_id')
    op.drop_table('image_resource')
    # ### end Alembic commands ###

Upgrade works great, but when I tried to downgrade I got issue: if len(ident) > self.max_identifier_length: TypeError: object of type 'NoneType' has no len() at sqlalchemy/engine/default.py, line 444.

If I manually specify foreign key it works perfectly:

op.create_foreign_key('my_fk', 'category', 'image_resource', ['image_id'], ['id'])

op.drop_constraint('my_fk', 'category', type_='foreignkey')

Is this behaviour is issue?

@zzzeek zzzeek added the question usage and API questions label Jul 19, 2019
@zzzeek
Copy link
Member

zzzeek commented Jul 19, 2019

hi there -

it might be nice if alembic had a nicer error message for this case, however, the constraint name cannot be None for drop_constraint(). Otherwise how will the "DROP CONSTRAINT" command know which constraint to drop?

@zzzeek
Copy link
Member

zzzeek commented Jul 19, 2019

oh and as to why it's coming out as None, you aren't using a naming convention, please see https://alembic.sqlalchemy.org/en/latest/naming.html

@zzzeek zzzeek added the missing behavior not quite a feature and not quite a bug, somehting we need to support label Jul 19, 2019
@zzzeek zzzeek changed the title Failed to downgrade with generated migration drop_constraint etc. should check for name=None and emit informative error message since this is common w/ autogenerate Jul 19, 2019
@zzzeek zzzeek added op directives and removed question usage and API questions labels Oct 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
missing behavior not quite a feature and not quite a bug, somehting we need to support naming convention issues op directives
Projects
None yet
Development

No branches or pull requests

2 participants