Replies: 1 comment
-
Sorry about the format.
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
First Check
Commit to Help
Example Code
Description
The Mask and Suit share the "ForeignKey" instance which cause the error below.
Could we have "sa_column_factory" in parameters of "Field" which i thought a more general solution to mix-in sqlalchemy Column with sqlmodel. Then the solution of the problem could be.
`
def refer_to_hero_id():
return Column(ForeignKey(Hero.id, ondelete="CASCADE"), primary_key=True)
class HeroItem(SQLModel):
hero_id: int = Field(sa_column_factory=refer_to_hero_id)
File "G:\test\venv\Lib\site-packages\sqlmodel\main.py", line 474, in new
col = get_column_from_field(v)
^^^^^^^^^^^^^^^^^^^^^^^^
File "G:\test\venv\Lib\site-packages\sqlmodel\main.py", line 661, in get_column_from_field
return Column(sa_type, *args, **kwargs) # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "G:\test\venv\Lib\site-packages\sqlalchemy\sql\schema.py", line 2145, in init
self._init_items(*cast(_typing_Sequence[SchemaItem], l_args))
File "G:\test\venv\Lib\site-packages\sqlalchemy\sql\schema.py", line 231, in _init_items
spwd(self, **kw)
File "G:\test\venv\Lib\site-packages\sqlalchemy\sql\base.py", line 1324, in _set_parent_with_dispatch
self._set_parent(parent, **kw)
File "G:\test\venv\Lib\site-packages\sqlalchemy\sql\schema.py", line 3213, in _set_parent
raise exc.InvalidRequestError(
sqlalchemy.exc.InvalidRequestError: This ForeignKey already has a parent !
`
Operating System
Windows
Operating System Details
No response
SQLModel Version
0.0.16
Python Version
3.11
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions