Vitalii Mytenko
Vitalii Mytenko

Reputation: 772

How to run commands in CLI with Railway.app

I have Django project deployed to Railway.app. I've installed Railway CLI, but can't understand how to run python manage.py makemigrations and so on in its CLI to make Django runnig.

My laptop is running Windows 10 Home.

Ho do I?

UPDATE. Some results from the answers:

In settings.py use Railway's DB. In this case you don't need to run CLI commands via Railway CLI, you may use local and it will affect the Railway's DB.

  1. In case you are using dev DB, that is different from Railway's linked to project.
  2. railway login
  3. railway link your_railway's_project_Id
  4. railway status to check whether you are in the right project
  5. railway run python manage.py createsuperuser
  6. This will affect Railways's DB

railway run python manage.py collectstatic make migrations migrate still don't run on remote server.

In Procfile I used code:

web: python manage.py migrate && gunicorn project_name.wsgi

Upvotes: 7

Views: 11829

Answers (3)

Adam
Adam

Reputation: 1

You can add python manage.py makemigrations as a command during your pre-deploy step.

Steps to complete as of Feb 2025:

  • Navigate to your project on Railway
  • Click the service you want to run the command
  • In the pop up menu, navigate to Settings
  • Scroll to find the Deploy section.
  • Click the Add pre-deploy step button underneath the Custom Start Command section.
  • Paste your command & Deploy changes

Other comments suggest you should use railway run to run the command. This is not true.

The railway run command as described on the docs here and here state that the command injects secrets from your service environment on Railway into your local environment. This does not allow you to run commands directly in the Railway environment as if accessing the server via SSH, but rather allows you to run your service locally with all the environment variables required.

Upvotes: 0

Baldráni
Baldráni

Reputation: 5638

So, you should run IN YOUR PROJECT REPOSITORY :

  • railway link -> Then select your project
  • railway run <your command>

Upvotes: 3

Victor Joseph
Victor Joseph

Reputation: 39

you can do that by using railway run (command to be executed)

for example to create a superuser, use railway run python manage.py createsuperuser

Check out this article

PS: Ensure you are in the same directory as that of the production because it will run both on local and production environment.

Upvotes: 3

Related Questions