About Huge Data Migrations
By default, Django wraps each migration in a transaction on databases that support transactions (like PostgreSQL). For huge data migrations, set atomic = False on the Migration class so rows are committed in batches rather than held in one enormous transaction that balloons memory.
class Migration(migrations.Migration):
atomic = False
# ...
The combination of atomic = False, chunked processing, idempotent logic, and raw SQL where possible will handle most cases without needing more RAM.
Tips and Tricks Programming Development Databases Django 6.x Django 5.2 Django 4.2 PostgreSQL MySQL Migrations
Also by me
Django Messaging
For Django-based social platforms.
Django Paddle Subscriptions
For Django-based SaaS projects.
Django GDPR Cookie Consent
For Django websites that use cookies.