good afternoon.
Just invert the inheritance order of the first two classes, as well as the inheritance of SQLModel as below:
Your code
class UserRead(SQLModel):
id: uuid.UUID
class UserBase(UserRead):
full_name: str
email: EmailStr
is_active: bool = True
is_superuser: bool = False
Below is my code
from typing import Optional
from datetime import datetime
from sqlmodel import Field, SQLModel
class AutoExecutaBaseId(SQLModel):
"""
BASE DATA MODEL - Auto-execute table
"""
id: Optional[int] = Field(default=None, primary_key=True)
class AutoExecutaBase(AutoExecutaBaseId):
"""
BASE DATA MODEL - Auto-execute table
"""
state: bool = Field(default=False, nullable=False)
next_execution: Optional[datetime] = Field(default=None, nullable=True)
class AutoExecuta(AutoExecutaBase, table=True):
"""
ORM DB MODEL - Auto-execute table
"""
__tablename__ = 'auto_execute'
class AutoExecutaPublico(AutoExecutaBase):
"""
PUBLIC MODEL - Auto-execute table
"""
pass
It will work!
Considering the mro() Method Resolution Order, first load the inheritance.
Therefore, to avoid having to mess with the resolution method with magic methods like new or any other means, just do this!
The logic is not to replicate table attributes, unless it is really necessary.
I also wished that the first column would be the id.
This is my table
[table with correct order][1] [1]: https://i.sstatic.net/lCzyVw9F.png
Thanks.