I would like to execute Django migrate command on azure app service in my application,
$ python manage.py migrate
but I have no idea how to do this.
As common scenario, we leverage virtual environment to handler python scripts as the official guide shows. If so, it may raise exceptions if we use the Azure Python runtime to run the commands because of lacking of dependencies.
Usually, we can leverage Kudu Console site of your Web Apps or Visual Studio Online extension to modifying scripts or executing commands.
https://<your_web_app_name>.scm.azurewebsites.net/DebugConsole
d:\home\site\wwwroot
which is the root directory of your application.env\Scripts\python.exe manage.py migrate
(assume your virtual environment is env
in the root directory)open console
button to open the cmdlet for commands, you can find this button in the left navigation bar.
Any further concern, please feel free to let me know.
You can run Python code inside your Azure web application. You have to make sure Python is enabled for the app though:
Then - you can probably wrap your call to python manage.py migrate
in a batch script and call it in the startup task for your webapp.
Startup tasks are described here: https://azure.microsoft.com/en-us/documentation/articles/cloud-services-startup-tasks/ and what it boils down to is that you have to bundle your batch script with your application, and modify the ServiceDefinition.csdef
and add the startup task in the XML like so:
<Startup>
<Task commandLine="Startup.cmd" executionContext="limited" taskType="simple" >
<Environment>
<Variable name="MyVersionNumber" value="1.0.0.0" />
</Environment>
</Task>
</Startup>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With