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

Can not run migrations with alembic. Socket error

Here i created a User model using sqlmodel. from sqlmodel import SQLModel, Field, Index from typing import Optional class User(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str =…
haku
  • 35
  • 5
0
votes
1 answer

SQLModel error: "AttributeError: 'Team' object has no attribute 'heroes'"

I'm trying to get my hands on Tiangolo's SQLModel and I tried the example code in this doc here : https://sqlmodel.tiangolo.com/tutorial/relationship-attributes/read-relationships/ The code is the following : from typing import List, Optional from…
ibi0tux
  • 2,481
  • 4
  • 28
  • 49
0
votes
0 answers

Python - using transition state machine in SQLModel

I want to use a state machine in my SQLModel schema but I'm getting type errors. class Invoice(BaseSQLModel, table=True): id: Optional[int] = Field(primary_key=True) def __init__(self): super().__init__() default_status =…
Dave Cook
  • 617
  • 1
  • 5
  • 17
0
votes
2 answers

Python SQLModel - Optional ID value for auto-increment causes type errors when retrieving from database

If I have a model like this: class MyModel(DBModel, table=True): id: Optional[int] = Field( primary_key=True) Then when saving new records to the database, the ID is automatically assigned, which is great. However, when I retrieve the model…
Dave Cook
  • 617
  • 1
  • 5
  • 17
0
votes
1 answer

SQLModel behaves differently from Pydantic BaseModel in exclude_unset

I have the following code snippet class Model(BaseModel): is_required: float a_float: Optional[float] = None k: Optional[int] = None k = Model( **{ "is_required": 0.1, "a_float": 1.2, } ) print(k.dict())…
nuitnuit
  • 3
  • 1
0
votes
1 answer

What is the correct way to return models to the list of entities owned by the related one?

I am doing a small project on Fastapi (my first project on it), python 3.10, using sqlalchemy, sqlmodel. I have 2 test models: shop and product. I want the endpoint shop to return the following structure: { "name": "Adidas", "id": 1, …
Gentleman
  • 1
  • 1
0
votes
1 answer

SQLModel: how to load specific columns?

I tried to load specific columns from a table via the following method: from sqlalchemy.orm import load_only from sqlmodel import (Field, Session, SQLModel, create_engine, select) from models import ( Tx ) engine = create_engine(url, echo=True) …
0
votes
0 answers

How to Initialise & Populate a Postgres Database with Circular ForeignKeys in SQLModel?

Goal: I'm trying to use SQLModel (a wrapper that ties together pydantic and sqlalchemy) to define and interact with the back-end database for a cleaning company. Specifically, trying to model a system where customers can have multiple properties…
Ayrton Bourn
  • 365
  • 5
  • 16
0
votes
1 answer

CreatedAt mixin (base class) in python SQLModel

I'm using SQLModel and would like to define base class with created_at field to inherit from it in others models. class CreatedAtMixin(SQLModel): created_at: datetime = Field(default=datetime.now(timezone.utc), nullable=False) But when i'm…
Nikita
  • 376
  • 1
  • 10
0
votes
1 answer

How to storage data types like lists and dictionaries into a postgres database using SQLModel & FastAPI?

I'm trying to use FastAPI with SQLModel for writing to a Postgresql database. In this case I want to store the inference obtained from a transformer model for natural language processing into the database. As seen below, I defined an SQLModel for…
0x55b1E06FF
  • 538
  • 1
  • 9
  • 24
0
votes
1 answer

Operator 'contains' is not supported on this expression (SQLModel)

I'm making a GraphQL api with strawberry using SQLModel as the database manager. I'm trying to get a list of items where a substring is in a string so I did this def resolve_user(id: int): with Session(engine) as session: user =…
Maypher
  • 90
  • 1
  • 11
0
votes
1 answer

SqlModel : Fastapi AttributeError: type object 'AddressBaseCore' has no attribute '__config__'

I am new to fastapi and SQLModel, i was trying to implement some basic code from my existing lib, I have an Address Class like @dataclass class Address(DataClassJsonMixin): addr1: str city: str province: str I simply want to create a…
s_mj
  • 530
  • 11
  • 28
0
votes
2 answers

FastAPI - badly formed hexadecimal UUID string

I'm using FastAPI & SQLModel to insert data into SQLite database (I'm posting a few fields, then SQLModel adds UUID and datetime fields and inserts into db). While posting data to FastAPI, I occasionally get ValueError: ValueError: badly formed…
help-ukraine-now
  • 3,850
  • 4
  • 19
  • 36
0
votes
0 answers

fast api depends SQL connection

I'm new in fast api. I'm trying to get user from my table but getting this error: user = await db.query(User).filter(User.login == data['login']).first() AttributeError: 'Depends' object has no attribute 'query' here is my…
Charwisd
  • 53
  • 9
-1
votes
1 answer

How can I log sql queries in the SqlModel?

How could I see/log queries sent by sqlmodel to database.
Atilla Ozgur
  • 14,339
  • 3
  • 49
  • 69
1 2 3
11
12