7,051 questions
0
votes
0
answers
27
views
How to connect to MySQL database with SQLAlchemy when running the application and MySQL running as a Docker container? [duplicate]
I am trying to run an application as its Docker image. It needs to access the database on the server. I am trying to run everything on a remote server and it is a Linux server. I am using docker ...
1
vote
0
answers
86
views
Memory Leak in Flask-SQLAlchemy 2.5.1 with SQLALCHEMY_RECORD_QUERIES - sqlalchemy_queries List Growing Indefinitely
Environment
Flask: 2.0.3
Flask-SQLAlchemy: 2.5.1
SQLAlchemy: 1.4.41
Deployment: Gunicorn with thread workers
Traffic: ~4 RPS in production
Observed Issue: Memory grows from 35-40% to 90% over 30 ...
1
vote
0
answers
89
views
SQLalchemy NOT NULL constraint failed on primary key
I am making an inventory database using SQLalchemy, but have some struggles with it. My code looks like this:
@cross_origin
@app.route('/api/add_item_loan', methods=['POST'])
def add_item_loan():
...
1
vote
1
answer
64
views
Flask SQL model missing one positional argument
from flask import (Flask, render_template)
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://user:password@localhost/database'
db = ...
0
votes
3
answers
72
views
whenever i hit post request on my page then I cannot display the updated value from database even though I fetched the data from updated db
This is my code and inorder to fetch the correct result i have to either refresh or render the user.html again to reflect the changes.
is there any way to do it more efficiently
I tried rendering the ...
2
votes
2
answers
110
views
How to convert a datetime to period
How can I format a datetime in HTML from flask render_template so it displays how much time has passed since the datetime?
I am getting cabinet table from flask_sqlalchemy where the date is formatted ...
0
votes
0
answers
32
views
How to copy all attributes from one row to another existing row with SQLAlchemy ORM [duplicate]
I'm trying to implement a profile-based persistent config for a webapp using flask-sqlalchemy. My idea is to back this using a ConfigProfiles table that will contain all admin-created profiles plus a &...
0
votes
1
answer
41
views
how to query a flask sqlalcheme tha has two relationship from another single table
I am trying to query a table that contains userId, which references users, and taggedNameId, which also references users and view it in my template. But i keep getting this error "int object' has ...
0
votes
1
answer
52
views
How can I access current_user outside of an route. FLASK API
Im trying to make a polling mechanism, so im making a background process using "ThreadPoolExecutor", I added a status boolean to my users table so they will only be able to send 1 request at ...
0
votes
1
answer
103
views
Getting AttributeError: 'tuple' object has no attribute 'items' while creating a new item in flask sql alchemy in flask admin
I have created two models in flask-sqlalchemy Product and Brand. Both have a relationship to each other. Whenever I try to create a brand I get the error AttributeError: 'tuple' object has no ...
0
votes
0
answers
52
views
RuntimeError: The current Flask app is not registered with this 'SQLAlchemy' instance
I'm having troubles to init my app on flask. It says "Did you forget to call 'init_app', or did you create multiple 'SQLAlchemy' instances?" I call init_app as "db.init_app(app)" ...
1
vote
1
answer
104
views
I cannot create table using SQLAlchemy
I have a table with a few columns in an empty database and then db.create_all() with with app.app_context()but when I run the code, the database is still empty and there are no tables.
CODE EDITOR: ...
1
vote
1
answer
73
views
Optimizing SQLAlchemy Flush: Intercepting INSERTs for Batched Multi-Row Execution in MySQL
Is there a way to monkeypatch SQLAlchemy in a way that intercepts all INSERT INTO statements generated during a session.flush() without sending them to the database? Instead, I want to capture these ...
0
votes
0
answers
31
views
Copy an sqlite database into memory using SQLAlchemy 3.2 [duplicate]
Martyn posted this 3 years ago; how to copy an SQLite db into memory:
Stackoverflow question
# open existing db
old_db = sqlite3.connect('app.db')
# get the connection to the in memory db
conn = db....
0
votes
0
answers
71
views
Cannot link python/flask app to sqlAlchemy
I am doing a course for my bootcamp in which I am being introduced to sqlAlchemy. I have followed along, restarted 2 or 3 times, and checked every little thing but I cannot get the two to link up.
...
0
votes
0
answers
105
views
sqlalchemy.exc.InterfaceError: Token is expired
sqlalchemy.exc.InterfaceError: (pyodbc.InterfaceError) ('28000', "[28000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Login failed for user '<token-identified principal>'. Token ...
0
votes
1
answer
66
views
SQLAlchemy Operation Error that goes away after refreshing
I'm using SQLalchemy in Flask. When I run the server (through Docker) and let the server be inactive for some time, I get the following error after making a request on the page.
OperationalError
...
0
votes
1
answer
51
views
How to query child tables belonging to particular parent
Is it possible to get one/all deep-nestend child tables in one-to-many hierarchy?
Say, a user has been logged.
u = db.session.execute(db.select(U).where(U.email == '[email protected]')).scalar()
And I'...
1
vote
0
answers
79
views
How can I modify the sqlalchemy query object's onclause directly?
I am using SQLAlchemy==2.0.37. I am developing an enhanced mixin and one of my needs is to modify the query object before compile. I have set up an event listener like so:
@event.listens_for(Query, &...
0
votes
0
answers
61
views
Flask CRUD not working for update form, returns blank
I'm new to Flask and working through a tutorial to create a CRUD app. I can add and delete fine but when I run the update, I land on my update page but the content is not appearing.
app.config['...
0
votes
3
answers
77
views
Regarding session in Flask
In below code I'm trying to fetch Sum of amount of expense using SQLALchemy on Dashboard, Query is Correct but didn't get session["user_id"] also tried to print user_id but didn't get any ...
0
votes
0
answers
26
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
34
views
__bind_key__ is not updating
I wanted to implement a flask app with multi tenant support.
I will get the tenant name from request header.
*
import os
from dotenv import load_dotenv
load_dotenv()
class Config:
# ...
0
votes
0
answers
38
views
I want custom types registered in sqlalchemy to be recognized as primitive types during migration
I created a type UUIDBinary to change uuid7 from string to binary when registering and binary to string when retrieving. model looks like this.
models/common.py
from uuid6 import UUID
from sqlalchemy....
0
votes
1
answer
74
views
Using SQLlite and SQLAlchemy how can I define a table to have TEXT and BLOB instead of VARCHAR?
this is my definition of my table.. not sure how to trigger it to make the column a TEXT or BLOB column instead of using VARCHAR all the time...
class Mailings(db.Model):
__tablename__ = 'mailings'...
0
votes
2
answers
54
views
How to delete records that are being selected at the same time using Flask-SQLAlchemy
I'm trying to mimic this query:
DELETE FROM files WHERE id IN (SELECT id FROM files WHERE patient_id=X);
But I fail to do it using this as this only deletes a single record:
obj = File.query....
0
votes
1
answer
116
views
How to handle DB sessions in pytest in Flask SQLAlchemy 3
I'm moving from Flask-SQLAlchemy 2 to 3.
As I understand the changes in Flask-SQLAlchemy 3, sessions are "scoped to the application context". I understand that to mean that every time you ...
1
vote
0
answers
84
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
2
answers
106
views
How do I create a both nullable and autoincremented column in SQLAlchemy?
I have a SQLAlchemy model like this:
class User(db.Model):
id: Mapped[int] = mapped_column(primary_key=True)
column: Mapped[int] = mapped_column(nullable=True, unique=True)
How can I make it ...
0
votes
0
answers
40
views
On the frontend the Select2 is not populating the fields for the user to select
I have an invoiceform to collect the date for postgresql database and Im having trouble with endpoints working properly and populating the drop down list for Salesman field and Product name field.
I ...
1
vote
1
answer
62
views
How to add Flask sqlalchemy multiple tables query result with column name & value into a list (to use with jsonify)
I have got 2 tables, one is department and another one is supplier. For every department, there could be a supplier or it could be none. So I use the outerjoin and the result is correct. I need to ...
0
votes
0
answers
29
views
OperationalError: table comment has no column named data while inserting a comment into my database
I’m encountering the following error when trying to insert a comment into my SQLite database:
Error says "table comment has no column named data" apparently meaning that the data column ...
0
votes
1
answer
70
views
Can I create a table in SQLAlchemy using a schema from a file/json file?
I have an object that needs to be stored in a Flask application running SQLAlchemy. I create the table when the application starts up. However the columns are based on an object that is created by a ...
1
vote
2
answers
686
views
How to correctly use pytest with Flask and SQLAlchemy
I am trying to create a pytest suite for my Flask app. To get myself started, I followed several tutorials, notably this, this, this, and this. Now, roughly 5 hours later, I am utterly defeated by the ...
0
votes
0
answers
70
views
Flask 403 Error: Unauthorized Access When Accessing '/get_class_codes' Route
I am encountering a 403 Forbidden error when trying to access the /get_class_codes route in my Flask application. Here's the error message I see in my logs:
2025-01-24 14:02:25,740 - INFO - 127.0.0.1 -...
0
votes
1
answer
348
views
Why does os.getenv work with other environment variables, but cannot retrieve Mysql password variable in .env file?
Im working on my flask backend api. I have a .env file in the directory with the following variables: CLIENT_ID, CLIENT_SECRET, MYSQL_PASSWORD, FLASK_APP. I use os.getenv("CLIENT_ID") and os....
0
votes
0
answers
51
views
SQLALCHEMY_BINDS doesn't work correctly with similar databases
I am creating a server using flask and sqlalchemy, but when I try to use SQLALCHEMY_BINDS, it is unable to use the values assigned during queries. I tried to make some more detailed logs to identify ...
0
votes
0
answers
42
views
How to create tables in postgreSQL using Flask and flask-sqlalchemy
I'm trying to create 3 tables on my postgreSQL database using Flask. I've defined the models, configured the database to start when Flask starts and defined the URI for the connection. Apparently ...
1
vote
1
answer
130
views
SQLAlchemy: Explicit set the order of object at session.merge()
I am using SQLAlchemy (with a Postgresql database).
I defined a database model with the following structure:
Table Family with the fields id and address.
Table Persons with id, name, family_id and ...
0
votes
1
answer
218
views
How to set default datetime value with SQLAlchemy?
I'm trying to set a default server value for a created_at column in a MySQL table with the SQLAlchemy library in Python 3.13. But, whenever I start up my Flask app and the table gets created, I run ...
0
votes
0
answers
160
views
Display the hive table results in UI using flask
I am new to Flask.
I have a Hive table called database_table with following fields:
id
field_id
table_name
schema_name
1
1
employee_table
employee
2
2
department_table
employeee
3
3
statistics_table
...
1
vote
1
answer
41
views
accessing sqlalchemy query filter results
I am developing my first Flask application.
In this application I have a put request from which I am querying the database. However I am not able to access and display the result of the query.
I have ...
0
votes
2
answers
95
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
0
answers
51
views
How can i make this default value work, since the value is a view with data being requested from the user?
So im making an app with flask with flask.sqlalchemy, flask-forms, flask-login, within that app i have varius models, and one of those is this:
from app import db
from sqlalchemy.orm import Mapped, ...
0
votes
1
answer
44
views
Flask-SQLAlchemy Multiple filters on Parent and Child
I have the following parent class:
class Pairing(Base):
__tablename__ = 'pairing'
id: Mapped[int] = mapped_column(Integer, unique=True, primary_key=True, autoincrement=True)
pairing_no: ...
0
votes
2
answers
424
views
I get this error - ImportError: DLL load failed while importing _psycopg: The specified module could not be found. what can I do about it?
I'm working on a Flask project with SQLAlchemy and PostgreSQL. When I try to run the Flask app, I encounter the following error:
Error: While importing 'app', an ImportError was raised:
Traceback (...
0
votes
0
answers
51
views
Failed to run Flask app after modify database model
Good day,
I am new to Flask. In the midst of developing my "to do list" app, I wanted to modify detail of "email" column in databases.py.
Below is databases.py:
from ...
0
votes
1
answer
377
views
Generically check server database version with SQLAlchemy
I've searched all over the internet and a handful of AI bots for what seems to me to be an extremely basic function, to no avail. What is the SQLAlchemy command to check the server database version?
I ...
0
votes
1
answer
40
views
Retrieving values from QuerySelectField and send to database - python
Basically I'm trying to send the form data from a queryselectfield to the database. The problem I am having is I can't seem to find a way to format the data so as not to show both the object name and ...
0
votes
1
answer
120
views
Getting: AttributeError: module 'mariadb' has no attribute 'paramstyle' with Flask SQLAlchemy
I'm trying to connect to a mariadb database using Flask SQLAlchemy but I am getting the following error:
AttributeError: module 'mariadb' has no attribute 'paramstyle'
Here's the function that ...