0

I am a beginner in working with databases, but I am working on myself). I use Makos, PayCharm, Python, Alembic, Postgre. I have already done all the preparations, namely, created and checked the operation of the virtual environment, created all the necessary files and dericotories (I will add a photo of the project architecture). At this moment, the task is to make the first command, namely - alembic revision --autogenerate -m "Database creation", after which I get an error (which is the title of the topic)

Problem details:

This is what the file looks like: Project/migrations/env.py

from logging.config import fileConfig
from sqlalchemy import engine_from_config
from sqlalchemy import pool
from alembic import context
from config import DB_HOST, DB_PORT, DB_USER, DB_NAME, DB_PASS
from models.models import metadata

config = context.config

section = config.config_ini_section
config.set_section_option(section, "DB_HOST", DB_HOST)
config.set_section_option(section, "DB_PORT", DB_PORT)
config.set_section_option(section, "DB_USER", DB_USER)
config.set_section_option(section, "DB_NAME", DB_NAME)
config.set_section_option(section, "DB_PASS", DB_PASS)

This is what the file looks like: Project/.env

DB_HOST=localhost
DB_PORT=5432
DB_NAME=postgres
DB_USER=postgres
DB_PASS=postgres

This is what the file looks like: Project/config.py

from dotenv import load_dotenv
import os

load_dotenv()

DB_HOST = os.environ.get("DB_HOST")
DB_PORT = os.environ.get("DB_PORT")
DB_NAME = os.environ.get("DB_NAME")
DB_USER = os.environ.get("DB_USER")
DB_PASS = os.environ.get("DB_PASS")

This is what the file looks like: Project/alembic.ini


[alembic]

script_location = migrations

prepend_sys_path = .

version_path_separator = os  # Use os.pathsep. Default configuration used for new projects.

sqlalchemy.url = postgresql://%(DB_HOST)s:%(DB_PORT)s@%(DB_PASS)s:%(DB_USER)s/%(DB_NAME)s


[post_write_hooks]

[loggers]
keys = root,sqlalchemy,alembic

[handlers]
keys = console

[formatters]
keys = generic

[logger_root]
level = WARN
handlers = console
qualname =

[logger_sqlalchemy]
level = WARN
handlers =
qualname = sqlalchemy.engine

[logger_alembic]
level = INFO
handlers =
qualname = alembic

[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic

[formatter_generic]
format = %(levelname)-5.5s [%(name)s] %(message)s
datefmt = %H:%M:%S

When I go to the file: .env and rearrange the value of the port, for example, to pass or name, the error is different, but the essence is similar!

0 Answers0