SQLAlchemy/SQLModel Relationship Error: sqlalchemy.exc.InvalidRequestError: Mapper 'Mapper[Users(users)]' has no property 'user' #1292
Unanswered
bilal-dev-bit
asked this question in
Questions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
First Check
Commit to Help
Example Code
Description
I’m encountering an error when trying to define and use relationships between my Orders and Users models using SQLModel. The error occurs when I attempt to create an order with a relationship to a user. The error message is:
sqlalchemy.exc.InvalidRequestError: Mapper 'Mapper[Users(users)]' has no property 'user'.
I’ve verified that the database tables are created correctly, and the relationships seem to be defined properly. However, SQLAlchemy is unable to resolve the user property in the Users model at runtime.
Code Snippets:
orders.py
users.py
orders.py from services package
gives an error on order_db = Orders.model_validate(order_data)
"
error message "sqlalchemy.exc.InvalidRequestError: Mapper 'Mapper[Users(users)]' has no property 'user'. If this property was indicated from other mappers or configure events, ensure registry.configure() has been called.
"
Operating System
Windows
Operating System Details
No response
SQLModel Version
0.0.22
Python Version
3.12.8
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions