Search code examples
djangoamazon-web-servicesmigrationansiblerds

Django and RDS change of models


How do I change database models and maintain the data already in an RDS instance? Right now I only know how to "change/migrate" models by connecting to an entirely new RDS instance and destroying the old one.

Django: 1.10.5 Python: 3.4 Deployment: Ansible playbooks, Upstart, Nginx RDS: PostgreSQL 9.5.4


Solution

  • The workflow is:

    1. [Optional] Generate an initial migration based upon your current model state (only if you don't already have one), then fake running that initial migration.
    2. Alter your models to the new desired state.
    3. Generate a migration for the new state.
    4. Run that migration on the existing database in RDS.