Some jobs happen once, by hand. Examples are updating the database, creating an admin user and fixing a batch of records. The Run a command box runs one command with your app's code, packages, secrets and saved data, and shows you what it printed.
Commands run in the published version of your app. An app that has never been published has nothing to run them in.
Open your app and go to the Tasks page. Type the command under Run a command, the way you would in a terminal. The buttons under the box fill in common commands for your framework.
| To do this | Run this |
|---|---|
| Apply Django database changes | python manage.py migrate |
| Create a Django admin user | python manage.py createsuperuser --noinput --username admin --email you@example.com |
| Apply Flask-Migrate database changes | flask db upgrade |
| Run a script from your project | python scripts/fix_prices.py |
| List the files your app has saved | ls -la /app/data |
| See installed packages | pip list |
Choose how long the command may run: 1 minute, 5 minutes, 15 minutes or 1 hour. Cloudilio stops the command when the time is up. Then press Run. The page shows a spinner and updates by itself when the command finishes.
You see everything the command printed, how long it took and one of three results.
Each app keeps its last 20 commands. Open Earlier commands to read any of them again, with the time and the person who ran it.
/app/data. Create a backup on the Data & backups page before a command that changes or deletes data.
A command has no keyboard attached, so it can't wait for you to type an answer. Pass every answer as an option or a secret. For Django, add --noinput.
To create a Django admin user, add a secret named DJANGO_SUPERUSER_PASSWORD on the Secrets page. Then run this command, and delete the secret afterwards.
python manage.py createsuperuser --noinput --username admin --email you@example.com
The box runs one program. Shell symbols such as &&, | and > don't work by themselves. To use them, give the whole line to a shell.
sh -c "python manage.py migrate && python manage.py clearsessions"
| Tool | When it runs | Where to find it |
|---|---|---|
| Run a command | Once, when you press Run | Tasks page |
| Run before each publish | Every publish, before the new version goes live | Overview page, Advanced settings |
| Scheduled task | On a timetable | Tasks page |
| Background worker | All the time | Tasks page |
"Publish the app first"
Publish your app once. After that, the box works.
"A command is still running"
Wait for the current command to finish or reach its time limit. Then run the next one.
"That command has a quote that is never closed"
Every " or ' needs a partner. Check the command for a missing quote.
The command stops with an error about input, or runs until its time limit
It is waiting for an answer nobody can type. Add the option that skips questions, such as --noinput or --yes.
"No such file or directory"
The command runs in your project's main folder. Give paths from there, such as python scripts/fix_prices.py. Use ls to see what is in the folder.
The command was force-stopped with exit code 137
It used more memory than your plan allows. Process records in smaller batches, or move to a plan with more memory.
Our post How to Run One-Off Commands in a Deployed Python App has more examples and six habits for working safely on live data.