About Huge Data Migrations
On databases like SQLite and PostgreSQL, all migration steps run inside one transaction by default. This means if something fails, everything is rolled back.
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 SQLite 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.