0

I'm working on a project that has both older sqlalchemy-migrate-based migrations and newer alembic-based migrations. I'm trying to remove the former. Ripping it out was easy enough but I'm seeing the following failure when I run some tests after doing so:

Traceback (most recent call last):                                                                                                                                                                             
                                                                                                                                                                                                                   
  File "/home/user/myproject/.tox/functional/lib/python3.7/site-packages/sqlalchemy/sql/elements.py", line 747, in __getattr__                                                        
return getattr(self.comparator, key)                                                                                                                                                                           
                                                                                                                                                                                                                   
AttributeError: 'Comparator' object has no attribute 'alter'

However, I note that when I re-add an import for the migrate (sqlalchemy-migrate) module into any of the remaining alembic migrations, things start working again? Why does the alter method disappar without this module?

stephenfin
  • 1,447
  • 3
  • 20
  • 41

1 Answers1

0

The reason for this was that one of the newer alembic migrations was using the alter method that sqlalchemy-migrate seems to monkey-patch in. Specifically, I needed to change the following:

images = Table('images', meta, autoload=True)
images.c.is_public.alter(nullable=True, server_default=None)

to:

with op.batch_alter_table('images') as batch_op:
    batch_op.alter_column('is_public', nullable=True, server_default=None)

(I had to do this instead of op.alter_column since that isn't compatible with SQLite).

stephenfin
  • 1,447
  • 3
  • 20
  • 41