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