"When I inherit an ORM model that contains fields of type list or dict, I encounter the error <class 'list'> has no matching SQLAlchemy type. Why does this happen?" #1346
-
First Check
Commit to Help
Example Codefrom sqlmodel import SQLModel, Field, JSON, Column
from typing import List
class BaseItem(SQLModel, table=True):
id: int = Field(default=None, primary_key=True)
methods: List[str] = Field([], sa_column=Column(JSON))
class DerivedItem(BaseItem):
pass DescriptionTraceback (most recent call last): Operating SystemLinux Operating System DetailsNo response SQLModel Version0.0.24 Python Version3.12 Additional ContextNo response |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
hi @GJCoke,
|
Beta Was this translation helpful? Give feedback.
-
@GJCoke tried ur case with generating migrations use table true in end-models and also sa_column can be tricky to inherit multiple times so sa_type is the solution:
all went fine hope it helped |
Beta Was this translation helpful? Give feedback.
@GJCoke tried ur case with generating migrations
use table true in end-models and also sa_column can be tricky to inherit multiple times so sa_type is the solution:
all went fine
migration for sa_type and sa_column is the same
hope it helped