mysql bigint id is defined using sqlmodel and cannot be inherited #939
-
First Check
Commit to Help
Example Codefrom sqlalchemy import BigInteger, Column
from sqlmodel import SQLModel, Field
from datetime import datetime
# parent class
class BaseMixinModel(SQLModel):
id :int = Field(description='id', title="id",sa_column=Column(BigInteger,primary_key=True))
create_time: datetime | None = Field(default_factory=get_current_time)
update_time: datetime | None = Field(
default_factory=get_current_time,
sa_column_kwargs={
'onupdate': get_current_time}, )
is_delete: bool = Field(default=False, )
class Admin(BaseMixinModel,table = True):
__tablename__ = 'tb_admin'
username :str = Field()
password :str = Field()
is_super :bool | None= Field()
last_login :datetime |None= Field(default=None) DescriptionFile "/usr/local/lib/python3.11/site-packages/sqlalchemy/orm/decl_base.py", line 578, in init I'm using sa_column=Column(BigInteger,primary_key=True) so I'm going to throw an error whenever my subclass inherits Operating SystemmacOS Operating System DetailsNo response SQLModel Version0.0.14 Python Version3.11 Additional Context![]() |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
you can't use So replace that line: id :int = Field(description='id', title="id",sa_column=Column(BigInteger,primary_key=True)) with this: id: int = Field(description='id', title="id", sa_type=BigInteger, primary_key=True) Using |
Beta Was this translation helpful? Give feedback.
you can't use
Column
in a parent class that is used by several tables because it will instantiate the column and the instance of a column cannot be used multiple times.So replace that line:
with this:
Using
sa_type
(orsa_column_args
orsa_column_kwargs
) won't instantiate the column right away and so the problem won't occur.