Migration error from postgres and django

I get this error anytime i run makemigrations:

/home/azeez/bendownselect/venv/lib/python3.12/site-packages/django/core/management/commands/makemigrations.py:160: RuntimeWarning: Got an error checking a consistent migration history performed for database connection 'default': could not translate host name "postgres" to address: Temporary failure in name resolution

and i get this error if i run migrate:

django.db.utils.OperationalError: could not translate host name "postgres" to address: Temporary failure in name resolution

this is my db config:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': env("POSTGRES_DB"),
        'USER': env("POSTGRES_USER"),
        'PASSWORD': env("POSTGRES_PASSWORD"),
        'HOST': env("POSTGRES_HOST"),
        'PORT': env("POSTGRES_PORT"),  
    }
}

Thank you!

1 Like

What is your environment setting for POSTGRES_HOST? What PostgreSQL server are you trying to connect to?

What do you think this error may be telling you?

I have no clue. I deleted my migrations folder and ran the steps it still gives the same error.

The postgres am using is a service from railway, i tried the one on my local machine also same error

Again:

Or, to clarify that second question, what is the host name or IP address for the PostgreSQL server you’re trying to use?

Also, see the docs for DATABASES to understand what these settings are supposed to do.

sorry this is how they look.

POSTGRES_HOST=monorail.proxy.rlwy.net
POSTGRES_PORT=34454
POSTGRES_DB=railway
POSTGRES_USER=postgres
POSTGRES_PASSWORD=password

And the PostgreSQL server you’re trying to use is at roxy.rlwy.net, listening on port 34454?

You’ll need to find some way to verify that, along with the database name and credentials.

What other ways have you connected to that database?

Through DBeaver-ce and it works.

Then the next step would be for you to post your complete settings file to ensure there’s not something else in that file causing a problem.

Also I might suggest you print the DATABASES setting after it’s defined for you to verify that the environment variables being used by the process are what you’re expecting them to be.

I got it fixed the error came from my .env because zsh loaded it before i added the new database credentials so i closed and opened it again and it works thank you.

I am getting the same error but I dont understand the solution, I’ve tried to change my dockerfile, docker-compose.yml, settings and reinstalled al the migrations.

These are my settings:

DATABASES = {
    "default": {
        "ENGINE": "django.db.backends.postgresql",
        "NAME": "simple_configurator",
        "USER": "admin",
        "PASSWORD": "admin",
        "HOST": "db",
        "PORT": "5432",
    }
}

docker compose:

version: '3.8'

services:
  db:
    image: postgres:latest
    environment:
      POSTGRES_USER: admin
      POSTGRES_PASSWORD: admin
      POSTGRES_DB: simple_configurator
    ports:
      - "5432:5432"

  web:
    build: .
    command: python manage.py runserver 0.0.0.0:8000
    ports:
      - "8000:8000"
    volumes:
      - .:/app
    depends_on:
      - db

and the error:

/home/jip/Projects/simpleConfigurator/.venv/lib/python3.11/site-packages/django/core/management/commands/makemigrations.py:160: RuntimeWarning: Got an error checking a consistent migration history performed for database connection ‘default’: [Errno -3] Temporary failure in name resolution

Dockerfile command:

CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]

Really, I spent days on this matter AGAIN (at first, last month) literally to close my prompt and everything runs okay. Thanks for the feedback.

Have you found the solution yet? I have the same problem