Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
First Check
Commit to Help
Example CodefromtypingimportOptional, ListfromsqlmodelimportField, SQLModel, Column, ARRAY, Stringfromdatetimeimportdatetime# This is a very basic model with more field and functions valid for all tables in this projectclassHeroBase(SQLModel):
id: Optional[int] =Field(default=None, primary_key=True)
name: str=Field(index=True)
secret_name: Optional[List[str]] =Field(sa_column=Column(ARRAY(String))) # <----age: Optional[int] =Field(default=None, index=True)
# This is a first aproximation of one type of table in the project (still could be a model for more projects)classModel_A(HeroBase):
favorite_color: Optional[str] =Field(max_length=12, default=None)
# This is also a first aproximation of one type of table in the project (still could be a model for more projects)classModel_B(HeroBase):
favorite_car: Optional[int] =Field(default=None)
# This is an especific table of this especific projectclassFirstGeneralHero(Model_A, table=True):
dateOfBorn: datetime=Field(default=datetime.utcnow())
# This is another especific table of this especific projectclassSecodGeneralHero(Model_B, table=True):
aField: str=Field(default='hello')DescriptionBefore I update to SQLModel 0.014, this kind of code run good. But now, when second table gonna be read, this error jump: "sqlalchemy.exc.ArgumentError: Column object 'secret_name' already assigned to Table 'firstgeneralhero'" I think the problem is over the field "secret_name", because it is an Array type and use sa_column. If you transform it into a string field, error disappear. It is my fault or it could be a bug or similar? Thanks!! Operating SystemmacOS Operating System DetailsNo response SQLModel Version0.014 Python Version3.12.0 Additional ContextTo produce de error, just create virtual environment and "pip3 install SQLModel".ç pip3 list: annotated-types 0.6.0 |
Replies: 4 comments 6 replies
Code run using "sa_type" instead "sa_column". |
I'm hitting this error myself. In my opinion, the issue seems to be that the sqlalchemy Column instance is being reused instead of copied to a new table when a Column instance is specified through sa_column. There doesn't seem to be a "column factory" alternative. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Same issue. In my case I can't switch to just using sa_type |
In newer versions of Maybe changing the type-hint for |
Code run using "sa_type" instead "sa_column".