Unable to run migrations for django web-application with Postgresql database.

Dodson, Arthur 1 Reputation point
2021-02-02T14:55:37.963+00:00

Hi,

I have followed this https://learn.microsoft.com/en-us/azure/developer/python/tutorial-python-postgresql-app-portal to deploy my web application onto Azure. I am struggling at the section "Run Django database migrations".

I've successfully deployed my code via Bitbucket, and all the relevant packages have been downloaded, when I click on my website URL this also brings up the login page of my website which is great!

But... I can't seem to run database migrations. I've opened the web ssh, gone into the directory "/home/site/wwwroot#" and activated the virtual environment via "source /antenv/bin/activate". I then try to run "python manage.py migrate" but I receive the error "ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?". So I run pip freeze to check what packages are there, and I'm missing all the packages within my requirements.txt. However, when I navigate to "cd /antenv/lib/python3.8/site-packages", all my packages (such as django) are present. So I'm really confused...! I've also tried to redeploy etc. (Worth noting that I've not had that much experience with deploying web applications.)

Any help or things to check for would be greatly appreciated.

Many thanks.

Azure Database for PostgreSQL
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
6,875 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Ryan Hill 25,666 Reputation points Microsoft Employee
    2021-02-05T21:13:24.987+00:00

    @Dodson, Arthur , I was able to get this work when I added my GitHub repo as a deployment source. This kicked off the build on the image and successfully created the virtual environment. What I did before was used Visual Studio Code to deploy the folder to the web app. This is perfectly fine, but you need to make sure you add SCM_DO_BUILD_DURING_DEPLOYMENT as an app setting set to 1. See https://learn.microsoft.com/en-us/azure/app-service/configure-language-python#customize-build-automation for more information.

    64781-dgtas5coro.gif

    Regards,
    Ryan