Skip to content

"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

Closed Answered by janas-adam
GJCoke asked this question in Questions
Discussion options

You must be logged in to vote

@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:

class BaseItem(SQLModel):
    id: int = Field(default=None, primary_key=True)
    methods: List[str] = Field(default_factory=list, sa_type=JSON)

class DerivedItem1(BaseItem, table=True):
    pass
    
class DerivedItem2(BaseItem, table=True):
    pass

all went fine
migration for sa_type and sa_column is the same

hope it helped

Replies: 2 comments 2 replies

Comment options

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

Comment options

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

Answer selected by GJCoke
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