AWS Django Elastic Beanstalk migration error

Viewed 580

Background

I created a website using Django and have it deployed on AWS EB with a MySQL Amazon RDS database. Recently I added a new field to one of the existing models in my models.py file. Everything worked fine on my local server (uses local SQLite, not RDS), but when I deployed the new update to EB I get the following error when I visit any page:

OperationalError at /
(1054, "Unknown column 'old_model.new_field' in 'field list'")

Question

What did I do wrong to get the error above and what can I do to fix it?

db-migrate.config:

container_commands:
  01_migrate:
    command: "django-admin.py migrate"
    leader_only: true
option_settings:
  aws:elasticbeanstalk:application:environment:
    DJANGO_SETTINGS_MODULE: app.settings
2 Answers

Creating a manual migration with python manage.py makemigrations, if this doesn't found any new changes in models try the same with your app name and then migrate the DB with python manage.py migrate

This should solve your issue. if this doesn't solve your issue, clear all the migrations file the again run makemigrations

  • I suspect migrations are not running properly.
  • Create an EC2 instance and try to run migrations on it connected to RDS instead of local sqlite DB.
  • Make sure your EC2 instance and RDS are on the same VPC.
  • After that deploy your app to EB.
Related