Skip to content
Discussion options

You must be logged in to vote
  1. Split schema into multiple files in a common models module.
  2. When referencing other models, use quotes (led_team: Optional["Team"])
  3. At the top of each file, import others like this:
# Generic imports here
from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from app.models.team import Team

# Models here
  1. Create a __init__.py file and add this:
def configure_relationships():
    """Call this after importing models to resolve relationships"""
    from sqlalchemy.orm import configure_mappers

    configure_mappers()
  1. When initializing your database (ie, running SQLModel.metadata.create_all(engine)), run configure_relationships() as well.

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by crummyh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
2 participants