Search code examples
pythondjangoamazon-web-servicesamazon-elastic-beanstalkrds

Error when adding new field to existing model in Django on Elastic Beanstalk using RDS


I'm getting an error when I try to add a new field to an existing model in Django. It's hosted on elastic beanstalk using a MySQL RDS database.

Here's the error when I try to access the model containing the new field:

(1054, "Unknown column 'existing_model.new_field' in 'field list'")

Is there a better way to treat migrations in Django on EB? Here's my .config file:

container_commands:
  01_makemigrations:
    command: "source /opt/python/run/venv/bin/activate && python manage.py makemigrations --noinput"
    leader_only: true
  02_migrate:
    command: "source /opt/python/run/venv/bin/activate && python manage.py migrate --noinput"
    leader_only: true
  03_createsu:
    command: "source /opt/python/run/venv/bin/activate && python manage.py createsu"
    leader_only: true
  04_collectstatic:
    command: "source /opt/python/run/venv/bin/activate && python manage.py collectstatic --noinput"

Any help? Thanks!


Solution

  • Turns out I had to run python manage.py makemigrations locally before eb deploy. That way, the migration files are created and when migrate is ran on the eb instance, it knows how to change the database accordingly.

    My .config file is now:

    container_commands:
      01_migrate:
        command: "source /opt/python/run/venv/bin/activate && python manage.py migrate --noinput"
        leader_only: true
      02_createsu:
        command: "source /opt/python/run/venv/bin/activate && python manage.py createsu"
        leader_only: true
      03_collectstatic:
        command: "source /opt/python/run/venv/bin/activate && python manage.py collectstatic --noinput"