Make Alembic detect column type changes and change the length of string fields
Auto Detect does not detect column type changes by default. You must turn this on by editing the alembic/env.py file.
By default Alembic does not change the length of string fields, I noticed this after changing a string field from:
description = Column(String(150), server_default='')
description = Column(String(250), server_default='')
No changes were made.
It appears that column type change detection is off by default, so you can test it first, and can be turned on by adding 'compare_type=True' to the context.
Edit the alembic/env.py file and add 'compare_type=True' at two places:
def run_migrations_offline(): ... context.configure( url=url, target_metadata=target_metadata, literal_binds=True, compare_type=True # <--- here ) ... def run_migrations_online(): ... with connectable.connect() as connection: context.configure( connection=connection, target_metadata=target_metadata, compare_type=True # <--- here ) ...
Now the column type changes will be detected and properly migrated.
- Docker containers suddenly using 192.168.0.0/16 instead of 172.17.0.0/16: services lost
- Two Flask apps, frontend and admin, on one domain using DispatcherMiddleware
- ISPConfig: running a Python Flask Docker container as a jailed Shell User
- Adding url_for() links to Jinja templates of a Flask multilanguage website
- Refining multilanguage: adding language fallback as an option
- Converting to a multilanguage database