I’m trying to deploy a FastAPI application on Render and I’m encountering an issue. When I attempt to deploy the application, I receive the following errors:
==> Exited with status 1
==> Common ways to troubleshoot your deploy: https://docs.render.com/troubleshooting-deploys
Skipping virtualenv creation, as specified in config file.
...
POSTGRES_USER
Field required [type=missing, input_value={}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.8/v/missing
POSTGRES_PASSWORD
Field required [type=missing, input_value={}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.8/v/missing
POSTGRES_PORT
Field required [type=missing, input_value={}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.8/v/missing
POSTGRES_DB
Field required [type=missing, input_value={}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.8/v/missing
POSTGRES_HOST
Field required [type=missing, input_value={}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.8/v/missing
POSTGRES_HOST_DOCKER
Field required [type=missing, input_value={}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.8/v/missing
DATABASE_URL
Field required [type=missing, input_value={}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.8/v/missing
ACCESS_TOKEN_SECRET_KEY
Field required [type=missing, input_value={}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.8/v/missing
ACCESS_TOKEN_EXPIRE_MINUTES
Field required [type=missing, input_value={}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.8/v/missing
REFRESH_TOKEN_SECRET_KEY
Field required [type=missing, input_value={}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.8/v/missing
REFRESH_TOKEN_EXPIRE_DAYS
Field required [type=missing, input_value={}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.8/v/missing
ALGORITHM
Field required [type=missing, input_value={}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.8/v/missing
...
Skipping virtualenv creation, as specified in config file.
.env
# PostgreSQL
POSTGRES_USER=postgres
POSTGRES_PASSWORD=55555
POSTGRES_PORT=5432
POSTGRES_DB=db_name
POSTGRES_HOST=localhost # delete later
# PostgreSQL for Docker
POSTGRES_HOST_DOCKER=db
DATABASE_URL=postgresql+asyncpg://{POSTGRES_USER}:{POSTGRES_PASSWORD}@{POSTGRES_HOST_DOCKER}:{POSTGRES_PORT}/{POSTGRES_DB}
# JWT
ACCESS_TOKEN_SECRET_KEY=some access token
ACCESS_TOKEN_EXPIRE_MINUTES=60
REFRESH_TOKEN_SECRET_KEY=some refresh token
REFRESH_TOKEN_EXPIRE_DAYS=30
ALGORITHM=HS256
Config
class Settings(BaseSettings):
TITLE: str = "App name"
VERSION: str = "0.0.1"
TIMEZONE: str = "UTC"
DESCRIPTION: str | None = None
DEBUG: bool = False
DOCS_URL: str = "/docs"
OPENAPI_URL: str = "/openapi.json"
REDOC_URL: str = "/redoc"
POSTGRES_USER: str
POSTGRES_PASSWORD: str
POSTGRES_PORT: int
POSTGRES_DB: str
POSTGRES_HOST: str
POSTGRES_HOST_DOCKER: str
DATABASE_URL: str
ACCESS_TOKEN_SECRET_KEY: str
ACCESS_TOKEN_EXPIRE_MINUTES: int
REFRESH_TOKEN_SECRET_KEY: str
REFRESH_TOKEN_EXPIRE_DAYS: int
ALGORITHM: str
IS_ALLOWED_CREDENTIALS: bool = True
ALLOWED_ORIGINS: list[str] = [
"http://localhost:3000",
"http://0.0.0.0:3000",
"http://127.0.0.1:3000",
"http://127.0.0.1:3001",
"http://localhost:5173",
"http://0.0.0.0:5173",
"http://127.0.0.1:5173",
"http://127.0.0.1:5174",
"https://render-url-here.onrender.com"
]
ALLOWED_METHODS: list[str] = ["*"]
ALLOWED_HEADERS: list[str] = ["*"]
model_config = SettingsConfigDict(env_file=".env", extra="allow")
docker-compose.yml
services:
db:
image: postgres:14
restart: always
environment:
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB}
volumes:
- postgres_data:/var/lib/postgresql/data
migrate:
build: .
command: poetry run alembic upgrade head
volumes:
- .:/app
depends_on:
- db
environment:
DATABASE_URL: postgresql+asyncpg://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST_DOCKER}:${POSTGRES_PORT}/${POSTGRES_DB}
web:
build: .
command: poetry run uvicorn app.main:app --host 0.0.0.0 --port 8000
volumes:
- .:/app
ports:
- "8000:8000"
depends_on:
- db
- migrate
environment:
ALGORITHM: ${ALGORITHM}
ACCESS_TOKEN_SECRET_KEY: ${ACCESS_TOKEN_SECRET_KEY}
ACCESS_TOKEN_EXPIRE_MINUTES: ${ACCESS_TOKEN_EXPIRE_MINUTES}
REFRESH_TOKEN_SECRET_KEY: ${REFRESH_TOKEN_SECRET_KEY}
REFRESH_TOKEN_EXPIRE_DAYS: ${REFRESH_TOKEN_EXPIRE_DAYS}
volumes:
postgres_data:
I tried deploying without the .env file and manually specifying the environment variables, but then I encountered a different problem with connecting to the database, which I didn’t have when deploying on my local machine. So, I decided to try it with the .env file.
123 123 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1