Questions tagged [sqlmodel]

Since SQL Model is a library that combines both SQL Alchemy and Pydantic, this tag is intended for only related questions to this library (SQLModel). Please be sure to tag SQL Alchemy and Pydantic related questions with the corresponding tags

SQLModel is a library for interacting with SQL databases from Python code, with Python objects.

It is designed to be intuitive, easy to use, highly compatible, and robust. SQLModel is based on Python type annotations and powered by Pydantic and SQLAlchemy.

171 questions
0
votes
0 answers

How to add methods dynamically to an instance of SQLModel class

I am trying to add functionality for conversion of timeseries data from one format to another based on the value type of the Element object, here, I am abstracting all that and just trying to print the type of conversion, I'd like to modify the…
yash
  • 331
  • 1
  • 3
  • 12
0
votes
0 answers

Getting "TypeError: cannot pickle 'module' object" exception when using a nested sqlalchemy field with sqlmodel

We are using sqlmodel 0.0.8 with a pre-existing sqlite database that has a column with Field(sa_column=sa.Column(sam.types.CompressedJSONType)) We are implementing a very simple rest API fetching data from the said database. This is the SQLModel…
0
votes
1 answer

SQLmodel: "UniqueViolation, duplicate key value violates unique constraint" on update

I have a fastapi edpoint for updating records in the database, but it doesn't seem to work as intended and I get the following error when I call the endpoint to update a record: File "/usr/src/app/app/api/controllers/records.py", line 137, in…
Saeed Esmaili
  • 764
  • 3
  • 12
  • 34
0
votes
1 answer

Fastapi and pgvector: InvalidRequestError: Unknown PG numeric type

I'm using pgvector, fastapi and sqlmodel to insert vectors to the database. from pgvector.sqlalchemy import Vector ## model class Record(SQLModel, table=True): id: UUID = Field(default_factory=uuid4, primary_key=True) text: str =…
Saeed Esmaili
  • 764
  • 3
  • 12
  • 34
0
votes
0 answers

Save a single instance of a class into an SQLModel? (FastAPI)

I'm on the way to create a fastAPI app and have some issues to become an simple SQLModel as a single instance into an other SQLModel. I think the way wasent wrong to do that, but still become an error, when im starting the Server (uvicorn) and…
0
votes
0 answers

SQLalchemy and factory_boy, object is assigned to another session

I've spent hours and still cannot figure it out. I'm receiving Object '' is already attached to session '2' (this is '1') My models: class Base(ORM): id: Optional[int] = Field(primary_key=True) created: datetime =…
kutasek69
  • 13
  • 3
0
votes
0 answers

Delete a row in a referred table when a record from which the referred row is created is deleted. What is the parameter for sqlalchemy.Relationship?

I am using pydantic, sqlmodel, fastapi and python. I have a few tables, e.g. Social, Email that adds a new record to VStatus table whenever a new record is created in them, e.g. a new record in Social creates a corresponding record in VStatus table.…
Jim
  • 450
  • 2
  • 10
0
votes
1 answer

Alembic - how to create hypertable

How to generate hypertable using Alembic? Some custom call must be added I suppose, but where? I tried event.listen but Alembic does not register it.
romanzdk
  • 930
  • 11
  • 30
0
votes
0 answers

Does SQLModel / Pydantic validation happen for PUT and PATCH classes if the validation is only on the primary db table class?

I'm building a FastAPI project with SQLModel, which uses Pydantic under the hood. I'm following the SQLModel style to create models. I have a base class and all other classes inherit from it, including the class that's tied to the database table.…
writes_on
  • 1,735
  • 2
  • 22
  • 35
0
votes
0 answers

fastapi/sqlmodel creates id column as having the last ordinal position if table class inherits from base class

Let's say my schemas.py looks like these: class EimBase(SQLModel): fimno: Optional[str] spv_component_id: Optional[int] eim_technology_name: Optional[str] eim_technology_version: Optional[str] obsolete_start_date:…
moth
  • 1,833
  • 12
  • 29
0
votes
0 answers

SQLMODEL fastAPI delete relationship table rows

I have two tables, DataBaseFirst and DataBaseSecond. I am maintaining a connection between two tables on a column session_id. What I want is that when i delete client_id in first table, the corresponding rows in table 2 should also be deleted. class…
Talha Anwar
  • 2,699
  • 4
  • 23
  • 62
0
votes
1 answer

FastAPI - SQLModel, Relationship and Insertion of New Row leading to Insertion of New Row in Another Table

Suppose I have two tables, Email and VStatus ('V' stands for 'Verification'). class Email(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) email: str vstatus_id: Optional[int] = Field(default=None,…
Jim
  • 450
  • 2
  • 10
0
votes
1 answer

Using SQLModel to have multiple tables with same columns

Let's say I have two SQL tables address and email tables. For the address table I may have the following generic fields: postal_code street_name and additionally, I would want the following two fields: is_verified, of type Enum with only one of…
Jim
  • 450
  • 2
  • 10
0
votes
1 answer

fastAPI SQLmodel MultipleResultsFound: Multiple rows were found when exactly one was required

This is my delete function. def delete_session(self,session_id: int, db): with Session(engine) as session: statement = select(db).where(db.session == session_id) results = session.exec(statement) sess =…
Talha Anwar
  • 2,699
  • 4
  • 23
  • 62
0
votes
0 answers

Order of columns in the table created does not have 'id' first, despite id being the first field in the SQLModel

I am creating a table using the following code: from sqlmodel import Field, SQLModel, JSON, Column, Time class MyTable(SQLModel, table=True): id: int | None = Field(default=None, primary_key=True) name: str type: str slug: str =…
epicwhale
  • 1,835
  • 18
  • 26