Questions tagged [sqlalchemy]

SQLAlchemy is a Python SQL toolkit and Object Relational Mapper that gives application developers the full power and flexibility of SQL.

Filter by
Sorted by
Tagged with
0
votes
0answers
12 views

SQLAlchemy find only parents that contain specific children

I have the following many-to-many models: class Association(db.Model): parent_id = db.Column(db.Integer, db.ForeignKey( 'parent.id'), primary_key=True) child_id = db.Column(db.Integer,...
0
votes
1answer
12 views

Create unique index with SQLAlchemy on Postgres using MD5

I have a column that can contain a long text, that I want to create a unique index on. I read on several places (for example here) that the way to do it is to create an index on the MD5 of the column....
0
votes
0answers
14 views

Polymorphism in Relationship Sqlalchemy

I have a SqlAchemy Model that have a relationship with a Single Table Inheritance, like this: @Schema(nested=['sensor', 'mad_version', 'serial_interface'], fields=('sensor',)) class Mad(sql.Model): ...
0
votes
0answers
6 views

Setting a default value of a QuerySelectField in a Flask WTForm

I have a Flask WTForm with a QuerySelectField, and would like to set the default value from the database. In the database I have a table for Jobs, and each job has a Status. class Job(db.Model): ...
0
votes
0answers
27 views

TypeError: 'Transaction' object is not iterable in Flask

I am trying to use a serializer to store my JSON data into DB. I have created an API and using in postman. Like : POST endpoint: API/transaction and data with JSON format Where I load into ...
0
votes
0answers
14 views

Flask SQLAlchemy Association Table: error creating backref

I have a Artist model, and a Venue model, and they have a many-to-many relationship facilitated by the Show model (the shows indicate the artist, venue and date of the concert). class Venue(db.Model):...
0
votes
2answers
23 views

sqlalchemy concat with more than 2 elements on Oracle DB

considering the following table definition meta = MetaData() tgd = Table('T_GROUP_DAT', meta, Column('C_ID'), Column('CLASS_CODE')) I create a select-statement using the ...
-1
votes
0answers
23 views

Sqlalchemy says column does not exist, even though it does [closed]

I have this model in sqlalchemy: class ForecastModel(Base, AllFeaturesMixin): __tablename__ = "forecast_model" __table_args__ = ( CheckConstraint( "predict_market = ANY (...
0
votes
0answers
15 views

Nested JSON Output of SQLAlchemy Query with Join

I have two tables Orders and OrderItems. It's a common setup whereby OrderItems has a foreign key linking it to Orders. So we have a one-to-many join from Orders to OrderItems. Note: Tables would have ...
0
votes
0answers
5 views

creating pool gives connection error if earlier connection was not created

I am using sqlalchemy ORM and pymysql driver to connect to db, I have discovered a behaviour that I do not understand, import os import pymysql from sqlalchemy.orm import Session from sqlalchemy ...
-1
votes
0answers
18 views

Filling textAreas on button click from database containing 3 related Tables(sqlAlchemy) [closed]

so I have the following structure: enter image description here Each validation section is related to the section that follows. So my question is: Having 3 tables: T1 that loads in validation1 T2 ...
0
votes
1answer
12 views

SQLAlchemy/Flask not showing records in table

Currently programming a small app in Flask for school. I made a DB and the I've put some data in there, simple nothing to worry about. I created a query to get all of the records out and show them ...
1
vote
0answers
29 views

SQLAlchemy - how to slice arrays to get the full range? [:] is compiled to [NULL:NULL]

I'm stuck at a specific problem with SQLAlchemy. Basically, I have a table with a column that is a nested array ({{filename1, file_url1}, {filename2, file_url2}}). I've managed to write a filter ...
0
votes
2answers
27 views

SQLAlchemy .execute() syntax for passing in variables

I'm trying to update column named dhl_team of my table players table for a specific row with ID 8476923 as an example. If I run: db.execute("UPDATE players SET dhl_team = 10 WHERE id = 8476923"); It ...
0
votes
1answer
21 views

Looking for a surogate for arrays in SQLLite , thru SQLAlchemy

I'm using SQLlite wit SQLAlchemy and I have values in database like: id name value 1 ionic "alpha, beta , gama, teta" I need to do a select query by name and values, using as params: name : ...
0
votes
0answers
12 views

Getting sqlalchemy.exc.OperationalError while trying to connect to MySQL database using Flask-SQLAlchemy

I am trying to connect to a MySQL database using PyMySQL driver and Flask-SQLAlchemy. However, I am getting the following error. sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (1045, ...
0
votes
1answer
18 views

How to count the number of rows from query with SQLAlchemy when no model is specified?

I'm looking for a way to count with SQLAlchemy the number of rows that is returned from a given query (that potentially includes filters) but everything I find on the net makes explicit use of a model ...
0
votes
0answers
16 views

How to detect changes in length of string in db.column flask sql-alchemy [duplicate]

I need to change the length of a db.String in my code: body=db.Column(db.String(300)) To: body=db.Column(db.String(400)) Flask Migrate doesn't detect the change when I migrate. I also need to push ...
0
votes
0answers
17 views

Return Child Model in Single Inheritance Table

I have Single Inheritance Table in SqlAlchemy and i wanna filter by id in parent table interface, have some way to return all child attributes using parent Model, this is my example: class ...
-1
votes
0answers
23 views

Data Ingestion from S3 to Postgres by Sqlalchemy ORM

This is related to my earlier post : Dynamic table creation SQLAlchemy ORM. After creating the table I am following the below steps for postgres ingestion. S3Bucket --> Pandas DataFrame --> to_dict ...
-1
votes
0answers
27 views

How can I have Many to Many relationship of multiple attributes from the same model with the other one in flask sqlalchemy?

I just started learning flask with this project where I'm trying to build an Inventory Management System. So here are my Entity Types and Entites: 1. Product (product_id) 2. Location (location_id) 3....
0
votes
1answer
26 views

Dynamic table creation SQLAlchemy ORM

I am new to SQLAlchemy ORM. I am trying to build a AWS S3 ingestion program which will ingest any CSV file from S3 bucket to Postgres through ORM. I am trying to read the first row of the CSV file and ...
0
votes
0answers
22 views

How to add new dialect to Alembic besides built-in dialects?

Alembic support 5 built-in dialects only: https://github.com/sqlalchemy/alembic/tree/master/alembic/ddl Now I want to manages schema in Apache Hive via alembic and noticed that PyHive supports ...
-3
votes
0answers
32 views

I want to Insert data into POSTGRESQL from csv file using python but error is coming “A value is required for bind parameter” [closed]

I want to Insert data into POSTGRESQL from csv file using python but error is coming "A value is required for bind parameter" import csv import os from sqlalchemy import create_engine from ...
1
vote
1answer
21 views

SQLAlchemy - How to create a one-to-many relationship with no items?

I'm trying to create an object in SQLAlchemy that can have a relationship with many items, but doesn't have to. Here is my models file: from sqlalchemy.ext.declarative import declarative_base from ...
0
votes
1answer
45 views

Compare two pandas data frames and get differences [closed]

I am currently having two pandas data frames. df1 :- Parsing an excel an getting data in a data frame and inserting this into Postgresql db. df2:- getting Postgresql table in a data frame. Now I ...
0
votes
1answer
27 views

Read MS SQL Server View to Pandas Dataframe

I am trying to read a MS SQL Server view to a pandas dataframe. At first I thought it was a table, so I wrote the following code (tables/views, server, database, ID and password have been changed to ...
0
votes
1answer
19 views

Python sqlalchemy password as asterix produce error

Error: sqlalchemy.exc.ProgrammingError: (mysql.connector.errors.ProgrammingError) 1045 (28000): Access denied for user 'root'@'localhost' Here is my code: class Read: def engine(self, password): ...
0
votes
0answers
12 views

Apache Airflow : airflow initdb command throws = (_mysql_exceptions.OperationalError) (1292, "Incorrect datetime value:)

I was following this article for installing Apache-airflow with mysql DB on Ubuntu. Apache Airflow with MYSQL File "/usr/local/bin/airflow", line 37, in <module> args.func(args) File "/...
0
votes
0answers
14 views

Tasks received but not inserting data in the database with Celery

I am running tasks with Celery but am having an issue, I have some dummy data to insert into the Postgres database, but, it's not inserting. I have also read a similar question, but still, it didn't ...
1
vote
0answers
16 views

using sqlalchemy to_sql when dataframe has different column names to sql server table column names

I have a dataframe that I upload to a SQL server table. I am using sqlalchemy & the to_sql method. The data uploads into the table perfectly. Currently I have designed it so that my column names ...
1
vote
1answer
37 views

(builtins.TypeError) SQLite Date type only accepts Python date objects as input

I Tried many ways of inserting date in my SQLAlchemy object. But gives error. My route file: app.route('/signup', methods=['POST']) def signup(): reply = {} try: data = request....
0
votes
0answers
18 views

SQL Alchemy: how many “Base = declarative_base()” statements are required?

I'm just starting to learn SQL Alchemy and for my first project my goal is to create two separate SQLITE DB files, each with one table. On my first attempt I tried the following: Base = ...
-1
votes
1answer
25 views

Flask sqlalchemy and mysql error when creating database

I'm trying to get my flask application to work with a mysql database instead of sqlite and got the following error when trying to create database with db.create_all() ModuleNotFoundError: No module ...
0
votes
0answers
11 views

SQLAlchemy reflect still seeing dropped table

Here is a simple code snippet that creates a table, reflects to show that table, then deletes the table and reflects again...but the table still shows up. If I log into the db, the table is definitely ...
0
votes
1answer
25 views

How can I establish a database relationship that allows different types of users to register in SqlAlchemy

I have different users that will access different funcionality in the plataform and have different information associated with them. I implemented the tables according to the diagram bellow, where I ...
0
votes
0answers
14 views

SQLAlchemy hybrid_property with expression

I want to query and filter by a hybrid_property. I understand that I need to use an expression, but I'm having trouble finding a way to accomplish this when the hybrid_property calls another a Python ...
0
votes
0answers
12 views

sqlalchemy connection issue while running docker image on local window machine

docker image builds successfully. But when actually I run docker image using docker run command to check if my application works fine. I got the below issue. Please need guidance over this issue. ...
0
votes
1answer
19 views

Dealing with multiple output results in UPSERT query [SQL]

I'm trying to do an update query in which a single row the table is updated and, if nothing has matched and updated, a new row is inserted. In each case, I need the query to return the ID of the ...
0
votes
0answers
33 views

Python ORM's: best practices

We often have performance issues with our ORM in Python (Fask-SQLAlchemy). Solutions to common performance issues are well documented (see this SQLAlchemy doc for example), but actions where you read, ...
0
votes
1answer
16 views

Pandas ignores dtype in function to_sql, giving TypeError: expecting string or bytes object

I'm processing data from an Excel spreadsheet and uploading it to Oracle. Pandas fails on the command to_sql with a certain edge case. I have a particular column COMMENTS which usually contains ...
2
votes
1answer
20 views

Sqlalchemy get data from relationship

I have this models class Post(Base): __tablename__ = 'posts' id = Column(Integer, primary_key=True) content = Column(Text) author = Column(Integer, ForeignKey('users.id')) ...
0
votes
0answers
11 views

ImportError : circular dependency with SQLAlchemy-Flask

I implemented my Flask application with the Factory design as done in this article and I use SQLAlchemy as done in this article. This leads to a circular dependency that I don't know how to solve. ...
0
votes
0answers
12 views

How to set the database name later to sqlalchemy engine?

I have a databases containing tables that were not created using SQLALchemy ORM, I just ran query in mysql terminal to create them, and for a while I was using mysql-connector and MySQLdb driver, now ...
0
votes
0answers
16 views

Alembic: Can't use literal_binds setting without as_sql mode

I'm using alembic to generate revisions using sqlalchemy. When running the command: alembic revision --autogenerate I get: ERROR [alembic.util.messaging] Can't use literal_binds setting without ...
0
votes
2answers
39 views

Sqlalchemy: How to update a column every 24 hours?

I am working on A REST API with python flask and I have implemented the following schema via sql-alchemy. from app import db from datetime import datetime from app.utilities.commons import * class ...
0
votes
1answer
19 views

Marshmallow ModelSchema to Mapping Class Inheritance SqlAlchemy

i am with this problem, i using ModelSchema to validade my API input and this give me a Database Model, it works fine, but if i use a Mapping Class Inheritance(Single Table type) the ModelSchema give ...
-1
votes
0answers
17 views

Error :from sqlalchemy import event, inspect, orm ImportError: cannot import name 'event'

When i try to work on flask_sqlachemy to create a data base I am getting this error. I am inside my virtual environment. I have Flask_sqlalchemy version 2.4.1 I have sqlalchemy version 1.3.12 This ...
1
vote
0answers
28 views

SQL alchemy table does not exist

I am writing on a Dash app and using SQL alchemy for the database. I want to make the creation of the database automated so I have a few lines of code to create the database if it does not exist. ...
0
votes
1answer
27 views

sqlalchemy create a column that is autoupdated depending on other columns

I need to create a column in a table that is autoupdated if one or more columns (possibly in another table) are updated, but it also should be possible to edit this column directly (and value should ...