R
Railway4mo ago
Chioma

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?
No description
168 Replies
Percy
Percy4mo ago
Project ID: N/A
Chioma
Chioma4mo ago
N/A
Chioma
Chioma4mo ago
Hi Brody!
Brody
Brody4mo ago
looks like python 3.7 is not supported anymore, wherever you are specifying that, specify python 3.8 instead
Chioma
Chioma4mo ago
okay i updated it to the python version i am using (3.12.1) the build was successful but the deploy logs have errors
Brody
Brody4mo ago
i suspect you continued to write to the legacy database after migrating but today your legacy database was shut down
Chioma
Chioma4mo ago
i updated my db config is that what you're referring to?
Brody
Brody4mo ago
can you send me the databases section of your settings.py?
Chioma
Chioma4mo ago
No description
Brody
Brody4mo ago
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
Chioma
Chioma4mo ago
and it will know to look for that information in railway?
Brody
Brody4mo ago
one step at a time
Chioma
Chioma4mo ago
okay i have done that step
Brody
Brody4mo ago
another screenshot please
Chioma
Chioma4mo ago
No description
Brody
Brody4mo ago
perfect when you migrated a month ago, did you change your settings.py file back then?
Chioma
Chioma4mo ago
no i didnt just did it now
Brody
Brody4mo ago
gotcha do you have any database service variables?
Chioma
Chioma4mo ago
yeah the info i hard coded there is data there i want to keep
Brody
Brody4mo ago
delete all database service variables please
Chioma
Chioma4mo ago
like this?
Chioma
Chioma4mo ago
No description
Chioma
Chioma4mo ago
you want me to delete my data here?
Brody
Brody4mo ago
nope please go and delete any database service variables on the website service
Chioma
Chioma4mo ago
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
Brody
Brody4mo ago
open the website service, go to the variables tab, do you have any database variables? if so, remove them
Chioma
Chioma4mo ago
No description
Brody
Brody4mo ago
please carefully read this message
Chioma
Chioma4mo ago
open the website service is that railway?
Brody
Brody4mo ago
yes
Chioma
Chioma4mo ago
go to the variables tab thats what im showing u on the screenshot
Brody
Brody4mo ago
thats the database service
Chioma
Chioma4mo ago
No description
Chioma
Chioma4mo ago
if youre not referring to this i am not sure what variables tab youre referring to
Brody
Brody4mo ago
please note that the name of that service is Database but i have asked you to open the Website service
Chioma
Chioma4mo ago
can you provide a screenshot i am confused sorry
Brody
Brody4mo ago
the only thing on your screenshot that says Website, please click it
Chioma
Chioma4mo ago
No description
Brody
Brody4mo ago
thank you
Chioma
Chioma4mo ago
thank u for your patience!
Brody
Brody4mo ago
respectufully, may i ask how you didn’t see the service named Website? how could i have explained that better?
Chioma
Chioma4mo ago
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
Brody
Brody4mo ago
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?
Chioma
Chioma4mo 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
Brody
Brody4mo ago
gotcha, thanks for confirming click on the Database Legacy plugin (the one that says plugin migrated) and then click the green re-migrate button
Chioma
Chioma4mo ago
do i re mgirate?
Chioma
Chioma4mo ago
No description
Brody
Brody4mo ago
yep
Chioma
Chioma4mo ago
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
Brody
Brody4mo ago
one step at a time
Chioma
Chioma4mo ago
okay sounds good it's still migrating im assuming before we can continue that needs to fully complete right?
Brody
Brody4mo ago
yes
Chioma
Chioma4mo ago
okay. is it okay if i check back in tomorrow ? i might call it a night
Brody
Brody4mo ago
yeah but whats the migration state right now?
Chioma
Chioma4mo ago
No description
Brody
Brody4mo ago
sorry i meant, what step of the process is it on
Chioma
Chioma4mo ago
it just shows me this again when i click it, so i don't know how to check the step it is on
Brody
Brody4mo ago
theres a blue button or something somewhere inside the legacy database that you can click
Chioma
Chioma4mo ago
it's done now
Brody
Brody4mo ago
did you still want to call it a night?
Chioma
Chioma4mo ago
i think so. i'm assuming there's a lot more yeah?
Brody
Brody4mo ago
if everything goes well, one more step
Chioma
Chioma4mo ago
ohh okay let's do it
Brody
Brody4mo ago
open the website service, click the variables tab, open the raw editor, paste this in
PGDATABASE=${{Database.PGDATABASE}}
PGUSER=${{Database.PGUSER}}
PGPASSWORD=${{Database.PGPASSWORD}}
PGHOST=${{Database.PGHOST}}
PGPORT=${{Database.PGPORT}}
PGDATABASE=${{Database.PGDATABASE}}
PGUSER=${{Database.PGUSER}}
PGPASSWORD=${{Database.PGPASSWORD}}
PGHOST=${{Database.PGHOST}}
PGPORT=${{Database.PGPORT}}
save, and deploy the changes
Chioma
Chioma4mo ago
deploy? i don't need to push the db changes live in the code first?
Brody
Brody4mo ago
you didnt push the updates to settings.py?
Chioma
Chioma4mo ago
no beause of this
Brody
Brody4mo ago
oh, yes please push the settings.py changes to github
Chioma
Chioma4mo ago
didnt work
Brody
Brody4mo ago
have you done this too?
Chioma
Chioma4mo ago
yeah
Chioma
Chioma4mo ago
No description
Brody
Brody4mo ago
that's not what I sent though
Chioma
Chioma4mo ago
are you not concerned that it doesn't work locally? should i try to resolve that?
Brody
Brody4mo ago
well first we need it get the setup on railway correct please use the raw variables I have provided
Chioma
Chioma4mo ago
adjusted!
Chioma
Chioma4mo ago
No description
Chioma
Chioma4mo ago
but still not working
Brody
Brody4mo ago
redeploy the website service please
Chioma
Chioma4mo ago
i did!
Brody
Brody4mo ago
okay and what doesn't work specifically
Chioma
Chioma4mo ago
the site doesn't work, and the deployment logs have erros and the web service displays "crashed"
Brody
Brody4mo ago
do you have psycopg2 in your requirements.txt?
Chioma
Chioma4mo ago
no i have psycopg2-binary i can add psycopg2 though okay app is up sort of haha
Brody
Brody4mo ago
sort of?
Chioma
Chioma4mo ago
the link works but when i try to use a login i know that is in the database i get this error
Chioma
Chioma4mo ago
No description
Brody
Brody4mo ago
show me your database settings in your settings.py please
Chioma
Chioma4mo ago
No description
Chioma
Chioma4mo ago
i get this error locally when i try to start my server too
Chioma
Chioma4mo ago
No description
Brody
Brody4mo ago
locally are you making sure to start the app via railway run?
Chioma
Chioma4mo ago
oh no. i was using python manage.py run server but when i just tried railway run still having some issues
Chioma
Chioma4mo ago
No description
Brody
Brody4mo ago
you need to provide the start command to railway run as that help printout points out
Chioma
Chioma4mo ago
not following sorry i need to type start railway run?
Brody
Brody4mo ago
do you have a .env file
Chioma
Chioma4mo ago
yes
Brody
Brody4mo ago
does it contain anything other than database variables?
Chioma
Chioma4mo ago
my database variable is ins ettings.py the .env has a databasue url
Brody
Brody4mo ago
is that all?
Chioma
Chioma4mo ago
yes
Brody
Brody4mo ago
your code doesn't use a database url, so please delete the .env file
Chioma
Chioma4mo ago
okay
Brody
Brody4mo ago
once deleted, you run your app locally with this command railway run python manage.py runserver
Chioma
Chioma4mo ago
same error
Brody
Brody4mo ago
screenshot please
Chioma
Chioma4mo ago
No description
Brody
Brody4mo ago
show me the command that was ran in your terminal please
Chioma
Chioma4mo ago
No description
Brody
Brody4mo ago
are you linked to your website service? run railway link
Chioma
Chioma4mo ago
ooo no what should i select when it asks for a service?
Brody
Brody4mo ago
the website service
Chioma
Chioma4mo ago
cool did that now im getting this error
Chioma
Chioma4mo ago
No description
Brody
Brody4mo ago
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
Chioma
Chioma4mo ago
oh u you know what they all say empty string
Chioma
Chioma4mo ago
No description
Brody
Brody4mo ago
interesting show me the raw variables again please
Chioma
Chioma4mo ago
No description
Chioma
Chioma4mo ago
do i also need to put those in the database service? or only web service
Brody
Brody4mo ago
nope, those should only be on the website service
Chioma
Chioma4mo ago
yeah thought so wouldnt really make sense conceptually
Brody
Brody4mo ago
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 word
Chioma
Chioma4mo ago
this yeah?
Chioma
Chioma4mo ago
No description
Brody
Brody4mo ago
yeah
Chioma
Chioma4mo ago
yeah no spaces or anything i retyped it
Brody
Brody4mo ago
well how much do you trust me? wanna add me to the project as an editor, because im stumped with just screenshots
Chioma
Chioma4mo ago
sure i can do that
Brody
Brody4mo ago
brodyover@gmail.com
Chioma
Chioma4mo ago
sent i might have to check back in the morning if that's okaythough
Brody
Brody4mo ago
yeah for sure, im an editor right?
Chioma
Chioma4mo ago
yup!
Brody
Brody4mo ago
cool, hopefully i can get this working
Chioma
Chioma4mo ago
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
Brody
Brody4mo ago
sounds good!
Brody
Brody4mo ago
well i dont get an error page, so i assume we good
No description
Brody
Brody4mo ago
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
Chioma
Chioma4mo ago
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?
Brody
Brody4mo ago
yeah you deleted service variables from the now deleted v2 Database service the new v2 database has the standard name of Postgres now
Chioma
Chioma4mo ago
ohh. so renaming it was an issue then also?
Brody
Brody4mo ago
no not at all, I just like it when it's named Postgres so that's what I did, didn't think you'd care
Chioma
Chioma4mo ago
no i don't mind! thanks for looking into it so you said i should delete the database legacy?
Chioma
Chioma4mo ago
No description
Brody
Brody4mo ago
as long as you confirm your app is in perfect working order with all the data in tact, yes you can delete it
Chioma
Chioma4mo ago
yup it is! just to confirm, delete like this?
Chioma
Chioma4mo ago
No description
Brody
Brody4mo ago
correct
Chioma
Chioma4mo ago
alrighty. it's deleted
Brody
Brody4mo ago
did you have any legacy database in any other projects on railway?
Chioma
Chioma4mo ago
yeah.. my portfolio (angular app)
Chioma
Chioma4mo ago
No description
Chioma
Chioma4mo ago
this is still working though unlike my python app was
Brody
Brody4mo ago
can you check the database related variables? do they reference the service named MongoDB?
Chioma
Chioma4mo ago
No description
Brody
Brody4mo ago
sorry I meant the database variables on the backend service
Chioma
Chioma4mo ago
No description
Brody
Brody4mo ago
open the raw editor, and show me the values please assuming it's using a reference variable you wouldn't be leaking anything
Chioma
Chioma4mo ago
No description
Brody
Brody4mo ago
perfect well then you can also delete the legacy database here, since you are already using the new database without issues I presume
Chioma
Chioma4mo ago
yup! works just fine thank you!!
Brody
Brody4mo ago
no problem!
Chioma
Chioma4mo ago
have a wonderful day!
Brody
Brody4mo ago
you too!