All Questions
Tagged with sqlalchemy python-3.x
1,505 questions
0
votes
1
answer
51
views
sqlite3.OperationalError: unable to open database file in virtual enviornment
I am trying to access a database named 'app.db' through sqlite3.connect() using a config with the URI of the file. I am also running this in a virtual enviornment and I am on windows.
Here is where I ...
0
votes
0
answers
16
views
How do I structure sqlalchemy cascade delets to remove what I want removed and leave the rest?
I am using python 3.12, the latest versions of flask, flask-sqlalchemy and sqlalchemy.
My project has a user table with an id field as in:
class User(Base):
__tablename__ = 'user'
id: Mapped[...
0
votes
1
answer
50
views
SQLAlchemy always fails with `invalid connection option` error
I am trying to connect with CockroachDB from Python using SQLAlchemy with SSL.
In the below code I have shown various combinations I tried.
I am getting error for all the combinations.
Program
import ...
0
votes
1
answer
18
views
How to effectively create an alias attribute for a given attribute
Given the following definition for my SqlAlchemy class:
class User(Base):
id = Column("user_id", String(60), primary_key=True)
user_name = Column("user_name", String(60), ...
0
votes
0
answers
21
views
SQLAlchemy>2 with Airflow venv operator fails
I have created a dag like this:
from airflow.operators.empty import EmptyOperator
from airflow.sensors.filesystem import FileSensor
from airflow.decorators import dag, task
def get_filepath(**...
1
vote
0
answers
51
views
SQLite database not being created in Flask instance folder despite db.create_all()
I have a Flask application with SQLAlchemy that was working fine until now. Suddenly, while the instance folder is being created, the database file isn't. I tried db.create_all() via shell, it works ...
0
votes
1
answer
40
views
How do I create a self joined table in SqlAlchemy for MySql
I am trying to create a self referencing table in MySql using SqlAlchemy. I get the error
TypeError: Additional arguments should be named <dialectname>_<argument>, got 'ForeignKey'
My ...
0
votes
0
answers
77
views
Relationships are both of the same direction when declaring two-way foreign keys
For my ORM classes Trade, Order and Account (of stock markets) I want Order and Trade linked to each other by a foreign key, while setting the column in order to be nullable (an order may not have a ...
0
votes
1
answer
60
views
Python SQLAlchemy Update Operation Yielded Unexpected Result
In Python(FastAPI) SQlAlchemy(sqlite) Update Operation Yielded Unexpected Result.
here the code
# schemas.py
class User(BaseModel):
uid: int
num: int
# model.py
class User(Base):
...
1
vote
1
answer
58
views
How to run tests in clear database and not delete existing data FastAPI SQLAlchemy Pytest
I've tried different ways to create a configuration for tests and encountered an issue: Tests persist data into my local database. If I drop database after running the tests I lose all my data in it.
...
0
votes
1
answer
77
views
why is sqllachemy returning a class instead of a string
So as part of learning sql alchemy I am querying the chinook database, following documentation and my lesson structure I believe I have setup the correct format for querying my tables.
### --- USING ...
0
votes
2
answers
77
views
Best way to chunk data from SQLAlchemy based on date?
Imagine this table:
class Entries(db.Model):
__tablename__ = "entries"
id = Column(Integer, primary_key=True, autoincrement=True)
name = Column(Text)
created_time = Column(...
0
votes
1
answer
33
views
Pushing data in Azure SQL Database works without docker but not with docker
I am trying to push a dataset by python & SqlAlchemy into Azure SQL database which works fine without docker but when I use with docker it throws an error. The error is :
2024-12-09 16:11:53 Error ...
0
votes
0
answers
38
views
SQLAlchemy Updating ORM model after inserting it
async def upsert_record(record: Record) -> Record:
async with async_session() as session:
stmt = insert(Record).values(
record.to_dict()
).on_conflict_do_update(
...
0
votes
1
answer
52
views
One to Many doesn't remove foreign key on delete in SQLAlchemy
Here's the setup:
A User can have many images assigned (related_images), but can only have 1 profile image.
class Photo(Model):
__tablename__ = "photo"
id = Column(Integer, ...