Unable to connect to Postgres db. Django BE app
denistsh01
HOBBYOP

a year ago

I linked the backend service, I put the variables in be service and also on my local . i try to connect using this

DATABASES = {

'default': {

'ENGINE': 'django.db.backends.postgresql_psycopg2',

'NAME': os.environ.get('PGDATABASE'),

'USER': os.environ.get('PGUSER'),

'PASSWORD': os.environ.get('PGPASSWORD'),

'HOST': os.environ.get('PGHOST'),

'PORT': os.environ.get('PGPORT'),

}

}

i run command railway run python manage.py migrate ( after i did the makemigrations i have the tables on db service) and i get ...

...

etc

django.db.utils.OperationalError: [Errno 11001] getaddrinfo failed

Solved

37 Replies

denistsh01
HOBBYOP

a year ago

motivated-ambition


a year ago

I think you are looking for railway ssh -- python manage.py migrate


denistsh01
HOBBYOP

a year ago

Hi.

(env) PS C:\Users\toshd\Licenta - Copy (4)Chinezu\licentaRepo\backend> railway ssh -- python manage.py migrate

Traceback (most recent call last):

File "/app/manage.py", line 11, in main

from django.core.management import execute_from_command_line

ModuleNotFoundError: No module named 'django'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):

File "/app/manage.py", line 22, in

main()

File "/app/manage.py", line 13, in main

raise ImportError(

ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?

(env) PS C:\Users\toshd\Licenta - Copy (4)Chinezu\licentaRepo\backend>

with my env on


denistsh01
HOBBYOP

a year ago

From what i know from previous ticket one year ago railway run did the work


a year ago

railway run runs the command locally


denistsh01
HOBBYOP

a year ago

after i linked it ( railway cli instaled also)


denistsh01
HOBBYOP

a year ago

ok gotcha.


denistsh01
HOBBYOP

a year ago

what do i need to do


denistsh01
HOBBYOP

a year ago

Project ID : ac9964b2-c042-43a4-8a28-e83db3a4a6ee


a year ago

I think - railway ssh -- source venv/bin/activate && python manage.py migrate


denistsh01
HOBBYOP

a year ago


denistsh01
HOBBYOP

a year ago

mb


denistsh01
HOBBYOP

a year ago

well it didnt work so i did railway shh then i will activate


denistsh01
HOBBYOP

a year ago

but i got Connected to interactive shell

root@bc6e63292d7d:/app#


denistsh01
HOBBYOP

a year ago

do i paste app id or what ?


denistsh01
HOBBYOP

a year ago

can i activate the venv now ?


denistsh01
HOBBYOP

a year ago

(env) PS C:\Users\toshd\Licenta - Copy (4)Chinezu\licentaRepo\backend> railway ssh

Connected to interactive shell

root@bc6e63292d7d:/app#

root@bc6e63292d7d:/app# source env/bin/activate

bash: env/bin/activate: No such file or directory

root@bc6e63292d7d:/app# .\env\Scripts\Activate.ps1

bash: .envScriptsActivate.ps1: command not found

root@bc6e63292d7d:/app# ls

accounts dashboard_cron manage.py requirements.txt

api db.sqlite3 output_test.csv templates

api_payments dreptapp railway.json

root@bc6e63292d7d:/app#


denistsh01
HOBBYOP

a year ago

??


denistsh01
HOBBYOP

a year ago

i entered on the service and it says Assign it the following value:

${{ peDreptDB.DATABASE_URL }}

3

Use the variable in your application code.


denistsh01
HOBBYOP

a year ago

but for what i use that


a year ago

  1. railway ssh
  2. . /opt/venv/bin/activate
  3. python manage.py migrate

denistsh01
HOBBYOP

a year ago


denistsh01
HOBBYOP

a year ago

i ve tried manage.py migrate but then python manage.py migrate


denistsh01
HOBBYOP

a year ago

but the second step worked


denistsh01
HOBBYOP

a year ago

but python manage.py didn't


a year ago

remove the start command from the railway.json file please


denistsh01
HOBBYOP

a year ago

whole command or only the migrate part ?


a year ago

the json line itself


denistsh01
HOBBYOP

a year ago


denistsh01
HOBBYOP

a year ago

i did a project one year ago, 1 fe 1 be and i followed the instructions on that ticket (maybe i missed something) and it was railway login , link , shell , activated the venv then did the migrations


denistsh01
HOBBYOP

a year ago

but didnt run into this problems


a year ago

made some changes, lets see how those work


denistsh01
HOBBYOP

a year ago

i redeployed it now i will try again those 3 commands


a year ago

please dont


a year ago

you're all good, theres no need to run anything yourself anymore

1353744183898411112

1353744184254660732


denistsh01
HOBBYOP

a year ago

Ok


a year ago

!s


Status changed to Solved brody over 1 year ago


Welcome!

Sign in to your Railway account to join the conversation.

Loading...