0

Here i created a User model using sqlmodel.

from sqlmodel import SQLModel, Field, Index
from typing import Optional

class User(SQLModel, table=True):
    id: Optional[int] = Field(default=None, primary_key=True)
    name: str = Field(max_length=30)
    surname: str = Field(max_length=50)

docker-compose with postgres:

version: "3.4"
services:
  db:
    image: postgres:14.0-alpine
    restart: always
    container_name: test_db
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
      - POSTGRES_DB=testdb
    ports:
    - "5432:5432"
    volumes:
    - db:/var/lib/postgresql/data
volumes:
  db:

Now i am trying to create migrations with alembic revision with "alembic revision --autogenerate -m "msg""

But it falls with

  File "C:\Python3.10\lib\socket.py", line 955, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11001] getaddrinfo failed
haku
  • 35
  • 5

1 Answers1

0

The error indicates that the hostname cannot be resolved. Is your database running locally? Has your python file that holds the SQLAlchemy engine access to it?

I also see that you are running albemic from your global python installation (File "C:\Python3.10\), does that have the same dependencies as your python application? In any case, it is very advisable to use virtual environments to ensure you are developing with the same modules as you are running albemic migrations with.

JarroVGIT
  • 4,291
  • 1
  • 17
  • 29
  • Yes. it runs locally. But the probem was that I really specified the wrong host in **alembic.ini** in sqlalcemy.url varialbe. Thanks! – haku Jul 27 '22 at 20:06
  • Please accept the answer if it helped you fixing your problem, so others may find it easy to reproduce as well. – JarroVGIT Jul 27 '22 at 20:09