Django migrate does not create any migrations on Elastic Beanstalk

Viewed 285

As title says. Here is my .ebextestions/django.config (not included in .gitignore of course)

container_commands:
    01_migrate:
        command: "source /var/app/venv/*/bin/activate python3 manage.py migrate --noinput"
        leader_only: true
    02_collectstatic:
        command: "source /var/app/venv/*/bin/activate python3 manage.py collectstatic --noinput"
    03_createsu:
        command: "source /var/app/venv/*/bin/activate python3 manage.py createsu"
        leader_only: true

option_settings:
    aws:elasticbeanstalk:application:environment:
        DJANGO_SETTINGS_MODULE: "myApp.settings"
        PYTHONPATH: "/var/app/venv/staging-LQM1lest/bin:$PYTHONPATH"
    aws:elasticbeanstalk:container:python:
        WSGIPath: "myApp.wsgi:application"
    aws:elasticbeanstalk:environment:proxy:staticfiles:
        /static: static

packages:
  yum:
    git: []
    python3-devel: []
    mariadb-devel: []

setting.py file

# [...]

if 'RDS_HOSTNAME' in os.environ:
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',
            'NAME': os.environ['RDS_DB_NAME'],
            'USER': os.environ['RDS_USERNAME'],
            'PASSWORD': os.environ['RDS_PASSWORD'],
            'HOST': os.environ['RDS_HOSTNAME'],
            'PORT': os.environ['RDS_PORT'],
        }
    }

# [...]

cfn-init-cmd.log file

2020-10-24 19:06:58,897 P9954 [INFO] ************************************************************
2020-10-24 19:06:58,898 P9954 [INFO] ConfigSet Infra-EmbeddedPreBuild
2020-10-24 19:06:58,901 P9954 [INFO] ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2020-10-24 19:06:58,901 P9954 [INFO] Config prebuild_0_myApp
2020-10-24 19:07:03,679 P10119 [INFO] ************************************************************
2020-10-24 19:07:03,679 P10119 [INFO] ConfigSet Infra-EmbeddedPostBuild
2020-10-24 19:07:03,682 P10119 [INFO] ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2020-10-24 19:07:03,682 P10119 [INFO] Config postbuild_0_myApp
2020-10-24 19:07:03,690 P10119 [INFO] ============================================================
2020-10-24 19:07:03,690 P10119 [INFO] Test for Command 01_migrate        <<== Test succeded
2020-10-24 19:07:03,694 P10119 [INFO] Completed successfully.
2020-10-24 19:07:03,694 P10119 [INFO] ============================================================
2020-10-24 19:07:03,694 P10119 [INFO] Command 01_migrate
2020-10-24 19:07:03,697 P10119 [INFO] Completed successfully.            <<== Migration completed
2020-10-24 19:07:03,704 P10119 [INFO] ============================================================
2020-10-24 19:07:03,704 P10119 [INFO] Command 02_collectstatic
2020-10-24 19:07:03,708 P10119 [INFO] Completed successfully.
2020-10-24 19:07:03,715 P10119 [INFO] ============================================================
2020-10-24 19:07:03,715 P10119 [INFO] Test for Command 03_createsu
2020-10-24 19:07:03,718 P10119 [INFO] Completed successfully.
2020-10-24 19:07:03,719 P10119 [INFO] ============================================================
2020-10-24 19:07:03,719 P10119 [INFO] Command 03_createsu
2020-10-24 19:07:03,722 P10119 [INFO] Completed successfully.

When I open xyz.elasticbeanstalk.com/admin/ I get this message:

Exception Value: (1146, "Table 'ebdb.django_site' doesn't exist")

I connected to database locally and see that no table has been created so far by ython3 manage.py migrate user_auth --noinput command. (I already ran makemigrations on local and migrations folder is included in git)

I set all RDS variables are set into elastic beanstalk configuration. Database is not created alongside EB but separately and then connected it to EB.

I also ssh'ed to the EB environment and activated virtual environment using source /var/app/venv/*/bin/activate. Then I ran python3 manage.py migrate --noinput and got this error:

django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.

The reason for this error is IMO, 'RDS_HOSTNAME' in os.environ returns False and therefore database is not configured.

So, I ran /opt/elasticbeanstalk/bin/get-config environment and I saw all RDS prefixed variables in the list.

Then I ran python3 in the same environment to check the value of os.environ and can see only 'DJANGO_SETTINGS_MODULE' is available, but no RDS prefixed variables.

I am working on it since past 2 days, read thousands of related blogs, threads, docs and finally gave up :(. I would provide any other related information if needed.

0 Answers
Related