You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
from datetime import datetime
from typing import Optional
from sqlalchemy import ForeignKey, create_engine
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column, relationship, scoped_session, sessionmaker
from ..settings import DATABASE
class Base(DeclarativeBase):
pass
class Parent(Base):
__tablename__ = "parent_table"
id: Mapped[int] = mapped_column(primary_key=True)
children: Mapped[list["Child"]] = relationship(back_populates="parent")
class Child(Base):
__tablename__ = "child_table"
id: Mapped[int] = mapped_column(primary_key=True)
parent_id: Mapped[int] = mapped_column(ForeignKey("parent_table.id"))
parent: Mapped["Parent"] = relationship(back_populates="children")
My errors:
db.py:5: error: Module "sqlalchemy.orm" has no attribute "DeclarativeBase"
db.py:5: error: Module "sqlalchemy.orm" has no attribute "Mapped"; maybe "Mapper"?
db.py:5: error: Module "sqlalchemy.orm" has no attribute "mapped_column"
db.py:17: error: Missing positional argument "argument" in call to "RelationshipProperty"
db.py:24: error: Missing positional argument "argument" in call to "RelationshipProperty"
The text was updated successfully, but these errors were encountered:
When I create a database following this guide: https://docs.sqlalchemy.org/en/20/orm/declarative_styles.html
Mypy says imports are missing and missing argument. The code itself works but I get errors with mypy. I am using Python 3.9
My file:
My errors:
The text was updated successfully, but these errors were encountered: