Skip to content

Sharing class registry from declarative base to SQLModel to enable relationships #1495

Answered by byrman
jossefaz asked this question in Questions
Discussion options

You must be logged in to vote

According to the docs:

from sqlalchemy.orm import declarative_base

Base = declarative_base()

Is equivalent to:

from sqlalchemy.orm import registry

mapper_registry = registry()
Base = mapper_registry.generate_base()

So you could make them share a registry by doing this:

from sqlmodel.main import default_registry

Base = default_registry.generate_base()

But that seems low-level fiddling.

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@YuriiMotov
Comment options

Answer selected by YuriiMotov
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
4 participants
Converted from issue

This discussion was converted from issue #245 on August 12, 2025 12:10.