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
1 answer

How to run SQLAlchemy uploader coroutines inside sync alembic migrations?

I'm trying to populate my db with some data and to do so I'm making migrations in which I need to run async uploader that fetch files, parse it to SQLModel and insert to db with SQLAlchemy. I've initialized alembic as async and my env file is looks…
flintpnz
  • 41
  • 3
0
votes
0 answers

Varchar2 in SQLmodel schema wrong translation

I use an oracle database as a server into my application. My SQLModel schema looks like below: class HostOutput(SQLModel): name: str = Field(index=True) region: Optional[str] = None os_type: Optional[int] = None os_version:…
moth
  • 1,833
  • 12
  • 29
0
votes
0 answers

How to do a create endpoint with relationship with fastapi and sqlmodel?

In models, have a User that can have many roles and Role that can have many users (many-to-many): class UsersRoles(SQLModel, table=True): user_id: int = Field(foreign_key='users.id', primary_key=True) role_id: int =…
Joao Coelho
  • 2,838
  • 4
  • 30
  • 36
0
votes
2 answers

Could not assemble any primary key columns for mapped table SQLAlchemy

When im tyring to run my FastAPI application this error appears. sqlalchemy.exc.ArgumentError: Mapper mapped class DTabelle->dtabelle could not assemble any primary key columns for mapped table 'dtabelle' When i remove the file d_tabelle.py…
Emil
  • 3
  • 3
0
votes
2 answers

Using both pydantic models as response throws error

I have a fastapi implementation where the main.py is: @app.get( "/licence_ol/", summary="Query Licence info by product id", response_description="Successful Query", response_model=list[EvergreenOutput], tags=[Tags.items] ) def…
moth
  • 1,833
  • 12
  • 29
0
votes
0 answers

SQLModel Relationship that returns count of related objects

I'm working on a FastAPI application and using SQLModel with a Postgres backend. I have Post objects, each of which can be upvoted by Users. We represent this with a PostUpvote many-to-many relation between Users and Posts. So far, so boring. from…
rmehlinger
  • 1,067
  • 1
  • 8
  • 23
0
votes
0 answers

A many-to-many table with SQLAlchemy which links a table (Paper) to the same table (Paper)

I'm using SQLModel, which has SQLAlchemy underneath. I am trying to create a many-to-many relationship using a join table to link the model Paper back to other Paper objects via PaperSimilarLink. It's a "similar papers" function. class…
phil0s0pher
  • 525
  • 10
  • 21
0
votes
0 answers

releavence of creating index of field

I was going through SQL Model docs from typing import Optional from sqlmodel import Field, SQLModel, create_engine class Team(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str = Field(index=True) …
Alwaysblue
  • 9,948
  • 38
  • 121
  • 210
0
votes
1 answer

sqlmodel: adding an example to a Field()

In pydantic we can add an example to Fields, such as: Field(default=None, example="A very nice Item") Which will then be displayed in the swagger API docs: How do we do this in sqlmodel? Adding the key example to the Field class in sqlmodel returns…
ZAR
  • 2,550
  • 4
  • 36
  • 66
0
votes
0 answers

Python SQLModel reading nested One-To-Many relationship

I have a request table that is linked to a request_entity table by a One-To-Many relationship. Now each request_entity has a location_id, service_id and module_id, which are also respective tables. When querying against a request, I want to be able…
Ismail Farooq
  • 145
  • 1
  • 3
  • 13
0
votes
0 answers

Not able to map data from sql join to pydantic models in fastapi

I am trying to map data from sql join of two tables to pydantic model, but getting null value models.py class Countries(BaseModel): country_name: str = Field(None, alias="country_name") class Tools(BaseModel): tool_name:str = Field(None,…
code_10
  • 155
  • 1
  • 2
  • 10
0
votes
1 answer

Not able to get data for joining two tables in fastapi using sqlmodel

I am trying to join two tables in fastapi using sqlmodel repository.py def test(db: Session = Depends(get_db)): statement = select(Tool, CountryTool).where(Tool.tool_id == CountryTool.tool_id) results = db.exec(statement) return…
code_10
  • 155
  • 1
  • 2
  • 10
0
votes
0 answers

How to construct a graph in SQlModel?

I am trying to use SQLModel to create a graph Node that would keep it's connections/links in it so that it can be traversed and stored in the database. I started of upgrading the Node class defined in other SQL answer, which works fine but is…
0
votes
1 answer

SQLModel - Adding comments to a tables

I couldn't find in the docs or in examples on the web how to add a comment to a table, so that it's also written in the corresponding SQL DB when the schema is created. Is it possible in SQLModel? How?
user11696358
  • 356
  • 1
  • 15
0
votes
0 answers

Can't access model attributes from statement in SQLModel

I'm using SQLModel on my project with FastAPI. All worked perfectly until my requests "lost" their attributes. On another file with similar code, I can access attributes simply using subtask.order_nb as show in the SQLModel documentation. But now, I…
DamDam
  • 119
  • 1
  • 15