First Check
Commit to Help
Example Code
## code example
db_unit = models.CreateUnit(
unit = unit.unit,
unit_code = unit.unit_code,
unit_multiples = unit.unit_multiples
)
db_unit.createunittype = unit_types
session.add(db_unit)
await session.commit()
await session.refresh(db_unit)
## models
class CreateUnitType(SQLModel, table=True):
id: Optional[int] = Field(default=None, primary_key=True)
mass: str
volume: int
length: int
electric_current: str
units: List["CreateUnit"] = Relationship(back_populates='createunittype')
class CreateUnit(SQLModel, table=True):
id: Optional[int] = Field(default=None, primary_key=True)
unit: str
unit_code: str
unit_multiples: int
unit_type_id: Optional[int] = Field(default=None, foreign_key="createunittype.id")
createunittype: Optional[CreateUnitType] = Relationship(back_populates="units")
Description
I have two different models CreateUnitType, CreateUnit attached with unit_type_id field as foreign key to CreateUnitType table and the whole database is in postgres. I want to establish the Relationship feature but somehow whenever I try to run the query I get this following error -
AttributeError: Could not locate column in row for column '_sa_instance_state'
Operating System
Linux
Operating System Details
No response
SQLModel Version
0.0.4
Python Version
3.7.8
Additional Context
No response
First Check
Commit to Help
Example Code
Description
I have two different models CreateUnitType, CreateUnit attached with unit_type_id field as foreign key to CreateUnitType table and the whole database is in postgres. I want to establish the Relationship feature but somehow whenever I try to run the query I get this following error -
AttributeError: Could not locate column in row for column '_sa_instance_state'Operating System
Linux
Operating System Details
No response
SQLModel Version
0.0.4
Python Version
3.7.8
Additional Context
No response