Хотел посмотреть SqlAlchemy и подключить к своему приложению.
При попытке что то закомитить появляется эта ошибка.
Код:
from sqlalchemy import create_engine
from sqlalchemy import Column, ForeignKey, Integer, String
from sqlalchemy.orm import declarative_base, relationship
engine = create_engine("sqlite:///", echo=True, future=True, pool_pre_ping=True)
Base = declarative_base()
class Questionnaire(Base):
__tablename__ = "questionnaire"
id = Column(Integer, primary_key=True)
user = Column(String(30))
photo = Column(String(100))
about = Column(String(500))
sex = Column(Integer)
city = Column(String(30))
find = Column(Integer)
def __repr__(self):
return f"Questionnaire(" \
f"id={self.id!r}, user={self.user!r}, photo={self.photo!r}, about={self.about!r}, sex={self.sex!r}," \
f" city={self.city!r}, find={self.find!r}"
if __name__ == '__main__':
from sqlalchemy.orm import Session
with Session(engine) as session:
Spongebob = Questionnaire(
user='646546565',
photo='fgffggfdgdf',
about='Column(String(500))',
sex=1,
city='Column(String(30))',
find=1,
)
session.add(Spongebob)
session.commit()
traceback:
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: questionnaire
[SQL: INSERT INTO questionnaire (user, photo, about, sex, city, find) VALUES (?, ?, ?, ?, ?, ?)]
[parameters: ('646546565', 'fgffggfdgdf', 'Column(String(500))', 1, 'Column(String(30))', 1)]
(Background on this error at: https://sqlalche.me/e/14/e3q8)