Python Migration Errors
Python's two main migration tools — Alembic (SQLAlchemy) and Django's built-in migrations — each have common failure patterns.
Alembic: Multiple Heads
When branches create migrations independently:
alembic heads
# Shows multiple heads
# Create a merge migration
alembic merge -m "merge branches" head1 head2
alembic upgrade headAlembic: Autogenerate Misses Changes
Autogenerate doesn't detect everything. Check the generated file:
alembic revision --autogenerate -m "add user email"
# Always review the generated migration!Common misses: column type changes, constraint names, server defaults. Add them manually:
def upgrade():
op.add_column('users', sa.Column('email', sa.String(255)))
op.create_index('ix_users_email', 'users', ['email'])
def downgrade():
op.drop_index('ix_users_email', 'users')
op.drop_column('users', 'email')Django: Conflicting Migrations
python manage.py makemigrations --mergeDjango: Fake Migration
If the database already has the changes:
python manage.py migrate myapp 0005 --fakeCircular Dependencies
# Django — use string references
class Post(models.Model):
author = models.ForeignKey('users.User', on_delete=models.CASCADE)Alembic: Offline Mode for Review
# Generate SQL without running it
alembic upgrade head --sql > migration.sql
# Review, then apply manuallyBugsly captures migration errors during application startup, including the specific migration that failed and the database error message.
Try Bugsly Free
Track up to 100 issues per month on the free plan; events are not billed.
Get Started FreeRelated Articles
Fix AbortController Error in Svelte
Learn how to fix the AbortController error in Svelte. Step-by-step guide with code examples and solutions. Quick, practical guide for developers.
Read moreHow to Fix Proxy Error in Perl
Learn how to diagnose and fix the proxy error in Perl. Includes code examples and prevention tips.
Read moreHow to Fix Geolocation Permission Denied in Angular
Learn how to fix the Geolocation Permission Denied in Angular. Step-by-step guide with code examples.
Read moreHow to Fix CORS Policy Blocked Error in Node.js
Learn how to fix the CORS Policy Blocked Error in Node.js. Step-by-step guide with code examples.
Read moreFrom the same team
SEOBolt
Technical SEO and AI search audits with ready-to-apply fix plans.
Try SEOBolt →GrowFast
Domain in, qualified B2B leads out, with cold outreach and deliverability handled.
Try GrowFast →AutoShort
Turn a topic into a faceless short: AI script, voiceover and captions.
Try AutoShort →RemixViral
Paste a long video and get back the moments worth posting, cut vertical and captioned.
Try RemixViral →