Hi I was wondering how you can migrate changes from your model files to the db postgresql?
ringo
PROOP

2 years ago

Hi I was wondering how you can migrate changes from your model files to the db postgresql? Our Server is crashing right now because we changed our local model files and pushed it but it didnt change the database. How can we make sure that the database also migrates when we update our models locally?

Solved

16 Replies

ringo
PROOP

2 years ago

Need help asap, server down


2 years ago

You can run migrations locally while in your project folder with railway run [migration command]https://docs.railway.app/guides/cli#local-development

Or by simply sticking the desired migration command at the beginning of your services' pre-existing start command as many software deployments do, e.g [migration command] && [start command]


Status changed to Solved Railway almost 2 years ago


ringo
PROOP

2 years ago

What command do I have to stick as start command?


2 years ago

I have provided the syntax needed, you would have to insert the applicable migration and or start command into the correct locations as designated by the square brackets.


ringo
PROOP

2 years ago

sry for the confusion but we are using locally the command python manage.py migrate is this the command I will have to stick to the database start?


2 years ago

It would not be as your database's start command, please do not modify anything about that service as it is easy to break something there.

The new start command would be set on your app's service, and python manage.py migrate would be the applicable command to run migrations for a django app.

Edit: There seems to be an issue with formatting in these comments, please keep that in mind.


ringo
PROOP

2 years ago

okay thank you I wrote python manage.py migrate in our app startcommand I will let you know if it worked


2 years ago

Please keep in mind the syntax I mentioned previously: [migration command] && [start command]

If you are just running 'python manage.py migrate' as your start command, your service will not work.


ringo
PROOP

2 years ago

so would this be a proper way to migrate our database?: python manage.py makemigrations && python manage.py migrate && python manage.py runserver

Just for the syntax


2 years ago

No it wouldn't -

  • 'python manage.py makemigrations' should only ever be run locally when a modal changes, no need for the railway cli there.

  • 'python manage.py runserver' starts a development server, you would never want to run a development server on Railway for a whole list of reasons that I'm not going to get into now, please run your django app with gunicorn.


ringo
PROOP

2 years ago

Can you give us the exact command if you know it? So would it be: python manage.py migrate && ??
What is the start command for the server?


2 years ago

I would need more information for that, what is the name of the folder that contains your 'wsgi.py' file?


ringo
PROOP

2 years ago

mysite is the name.


2 years ago

Then your start command in Railway would be 'python manage.py migrate && gunicorn mysite.wsgi'

Make sure you have 'gunicorn' in your 'requirements.txt' file.


ringo
PROOP

2 years ago

Sorry for responding so late but this actually worked and we were able to restart the Server. Thank you so much you are the best brody


2 years ago

happy to help


Loading...