SQLalchemy выдаёт _run_ddl_visitor
Я написал следующий код:
import configparser
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, String, Boolean, ForeignKey, Table
from sqlalchemy import create_engine
config = configparser.RawConfigParser()
config.read("config.ini")
engine = None
# getting type of database
TypeOfDb = config.get("database", "type")
if TypeOfDb == "sqlite3":
# getting name
name = config.get("database", "name")
# string of connection
SQLALCHEMY_DATABASE_URL = f"sqlite:///./{name}.db"
engine = create_engine(
SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False}
)
elif TypeOfDb == "psql":
# name of DB
name = config.get("database", "name")
password = config.get("database", "password")
user = config.get("database", "user")
host = config.get("database", "host")
# string of connection
SQLALCHEMY_DATABASE_URL = f"postgresql://{user}:{password}@{host}/{name}"
engine = create_engine(SQLALCHEMY_DATABASE_URL)
class Base(DeclarativeBase):
pass
# define tables in the database
class User(Base):
__tablename__ = "user"
id = Column(Integer, primary_key=True, unique=True)
name = Column(String, unique=True)
email = Column(String, unique=True)
verificated = Column(Boolean)
class Store(Base):
__tablename__ = "store"
UserId = Column(Integer, primary_key=True, unique=True)
name = Column(String, unique=True)
INN = Column(String, unique=True)
store_id = Column(Integer, unique=True)
class Thing(Base):
__tablename__ = "thing"
StoreId = Column(Integer, primary_key=True, unique=True)
id = Column(Integer, primary_key=True, unique=True)
category = Column(String)
price = Column(Integer)
if __name__ == "__main__":
Base.metadata.create_all(bind=engine)
else:
SessionLocal = sessionmaker(autoflush=False, bind=engine)
db = SessionLocal()
Файл config.ini:
[database]
type = "sqlite3"
name = "main"
password = ""
user = ""
host = ""
[shop]
name = "SomeShop"
valute = "RUB"
lan = "RU"
При запуске файла с кодом напрямую появляется ошибка:
bind._run_ddl_visitor( ^^^^^^^^^^^^^^^^^^^^^AttributeError: 'NoneType' object has no attribute '_run_ddl_visitor'**
Вот здесь полный трейс ошибки: https://pastebin.com/B2M0CTuY