Python Deployment Error
Hello! I am looking for help deploying a Python Django project. My project was already deployed succesfullly, but I noticed after Railway did the database update that the build fail. I am not too sure what I need to correct to get it up and running again. I have attached a screenshot of the deploy error.
Can anyone assist please?
168 Replies
Project ID:
N/A
N/A
build logs please https://bookmarklets.up.railway.app/log-downloader/
Hi Brody!
looks like python 3.7 is not supported anymore, wherever you are specifying that, specify python 3.8 instead
okay i updated it to the python version i am using (3.12.1) the build was successful but the deploy logs have errors
i suspect you continued to write to the legacy database after migrating
but today your legacy database was shut down
i updated my db config
is that what you're referring to?
can you send me the databases section of your settings.py?
oh no, we dont want to hardcode sensitive information
https://github.com/railwayapp-templates/django/blob/main/mysite/settings.py#L81-L90
please update your settings.py file to the code highlighted here
and it will know to look for that information in railway?
one step at a time
okay i have done that step
another screenshot please
perfect
when you migrated a month ago, did you change your settings.py file back then?
no i didnt just did it now
gotcha
do you have any database service variables?
yeah the info i hard coded
there is data there i want to keep
delete all database service variables please
like this?
you want me to delete my data here?
nope please go and delete any database service variables on the website service
i guess i am not understanding. if the above isnt what youre referring to as a datbase service variable, then i think i do not have what you are asking
open the website service, go to the variables tab, do you have any database variables? if so, remove them
please carefully read this message
open the website service
is that railway?
yes
go to the variables tab
thats what im showing u on the screenshot
thats the database service
if youre not referring to this i am not sure what variables tab youre referring to
please note that the name of that service is
Database
but i have asked you to open the Website
servicecan you provide a screenshot
i am confused sorry
the only thing on your screenshot that says
Website
, please click itthank you
thank u for your patience!
respectufully, may i ask how you didn’t see the service named
Website
? how could i have explained that better?I think you explained it as clear as you could! I think it's just on me not associating that as a service. I would've maybe said click on the Crashed section
noted, thanks
so you are absolutely sure you have only updated the database credentials in your settings.py today only and not a month ago?
when railway swnt that update i clicked migrate in railway then a month ago
but i didnt change the variables in my code til today
i didnt realize they changed, like the port number, , url, etc
gotcha, thanks for confirming
click on the
Database Legacy
plugin (the one that says plugin migrated) and then click the green re-migrate buttondo i re mgirate?
yep
okay sounds good
before i do that though
my code has an issue with the new format of my db and is no longer working locally
one step at a time
okay sounds good
it's still migrating
im assuming before we can continue that needs to fully complete right?
yes
okay. is it okay if i check back in tomorrow
?
i might call it a night
yeah but whats the migration state right now?
sorry i meant, what step of the process is it on
it just shows me this again when i click it, so i don't know how to check the step it is on
theres a blue button or something somewhere inside the legacy database that you can click
it's done now
did you still want to call it a night?
i think so. i'm assuming there's a lot more yeah?
if everything goes well, one more step
ohh
okay let's do it
open the website service, click the variables tab, open the raw editor, paste this in
save, and deploy the changes
deploy?
i don't need to push the db changes live in the code first?
you didnt push the updates to settings.py?
no beause of this
oh, yes please push the settings.py changes to github
didnt work
have you done this too?
yeah
that's not what I sent though
are you not concerned that it doesn't work locally? should i try to resolve that?
well first we need it get the setup on railway correct
please use the raw variables I have provided
adjusted!
but still not working
redeploy the website service please
i did!
okay and what doesn't work specifically
the site doesn't work, and the deployment logs have erros and the web service displays "crashed"
do you have
psycopg2
in your requirements.txt?no i have psycopg2-binary
i can add psycopg2 though
okay app is up sort of haha
sort of?
the link works
but when i try to use a login i know that is in the database i get this error
show me your database settings in your settings.py please
i get this error locally when i try to start my server too
locally are you making sure to start the app via
railway run
?oh no. i was using python manage.py run server but when i just tried railway run still having some issues
you need to provide the start command to railway run as that help printout points out
not following sorry
i need to type start railway run?
do you have a .env file
yes
does it contain anything other than database variables?
my database variable is ins ettings.py
the .env has a databasue url
is that all?
yes
your code doesn't use a database url, so please delete the .env file
okay
once deleted, you run your app locally with this command
railway run python manage.py runserver
same error
screenshot please
show me the command that was ran in your terminal please
are you linked to your website service? run
railway link
ooo no
what should i select when it asks for a service?
the website service
cool
did that
now im getting this error
interesting, same error as on railway
go to the website service on railway, open the variables tab, click the eye icon on all variables to confirm they all display correctly
oh u you know what
they all say empty string
interesting
show me the raw variables again please
do i also need to put those in the database service? or only web service
nope, those should only be on the website service
yeah thought so wouldnt really make sense conceptually
so crazy idea,
Database
is not the default name for a database, meaning you renamed it at one point, maybe the name has some leading or trailing whitespace, so open the v2 database and edit it's name by going to the settings page and clicking the pencil icon besides it's name, make sure it's just Database
without any spaces around the wordthis yeah?
yeah
yeah no spaces or anything
i retyped it
well how much do you trust me? wanna add me to the project as an editor, because im stumped with just screenshots
sure i can do that
sent
i might have to check back in the morning if that's okaythough
yeah for sure, im an editor right?
yup!
cool, hopefully i can get this working
that'd be amazing! wasn't expecting this to bug out the way it did today. thanks for ur time as always brody
check back in with ya in the am
sounds good!
well i dont get an error page, so i assume we good
you had deleted crucial service variables from the database, causing the variable references on the website service to render blank.
i deleted the broken database and asked a team member to re-run the migration, since i can delete your stuff but i can't run a migration :kekw:
you should be good to go and you can delete the legacy database once you confirm that your app works
Hi Brody! Yeah it works on railway and locally. thanks so much
you said i deleted crucial service variables? i didn't realize..where did i delete these - in the database service?
yeah you deleted service variables from the now deleted v2
Database
service
the new v2 database has the standard name of Postgres
nowohh. so renaming it was an issue then also?
no not at all, I just like it when it's named
Postgres
so that's what I did, didn't think you'd careno i don't mind! thanks for looking into it
so you said i should delete the database legacy?
as long as you confirm your app is in perfect working order with all the data in tact, yes you can delete it
yup it is!
just to confirm, delete like this?
correct
alrighty. it's deleted
did you have any legacy database in any other projects on railway?
yeah.. my portfolio (angular app)
this is still working though unlike my python app was
can you check the database related variables? do they reference the service named
MongoDB
?sorry I meant the database variables on the backend service
open the raw editor, and show me the values please
assuming it's using a reference variable you wouldn't be leaking anything
perfect
well then you can also delete the legacy database here, since you are already using the new database without issues I presume
yup! works just fine
thank you!!
no problem!
have a wonderful day!
you too!