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?
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?
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
Most helpful comment
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