Код: Выделить всё
in get_property
raise sa_exc.InvalidRequestError(
sqlalchemy.exc.InvalidRequestError: Mapper 'Mapper[Users(users)]' has no property 'users_habit'. If this property was indicated from other mappers or configure events, ensure registry.configure() has been called.
Код: Выделить всё
from ..models import Base
from sqlalchemy.orm import Mapped, mapped_column
from sqlalchemy import String
class Users(Base):
__tablename__ = "users"
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
telegram_id: Mapped[int] = mapped_column(nullable=False)
username: Mapped[String] = mapped_column(String(50), nullable=False)
phone_number: Mapped[int]
Код: Выделить всё
from typing import List
from ..models import Base
from .users import Users
from sqlalchemy import ForeignKey
from sqlalchemy.orm import Mapped, relationship, mapped_column
class Habits(Base):
__tablename__ = "users_habits"
user_id: Mapped[int] = mapped_column(ForeignKey("users.id"))
user: Mapped["Users"] = relationship(back_populates="users_habit")
habit: Mapped[List[str]] = relationship(back_populates="users_habit")
Подробнее здесь: https://stackoverflow.com/questions/785 ... uest-error
Мобильная версия