Questions tagged [sqlalchemy]

1

votes
0

answer
97

Views

Docker-compose: bind Celery to Postgres database

My Docker app runs with Flaskas backend and Celeryas an asyncronous task manager. Task results are then dumped in a SQLalchemy database owned by Postgres. However, I am not being able to make Celery interact with Postgres. STRUCTURE docker-compose-dev.yml web/ entrypoint.sh celery_worker.py migrati...
data_garden
1

votes
1

answer
276

Views

Flask-sqlalchemy-Marshmallow nesting Schema not working

Basically what i want to do is, join 2 tables 'users' & 'company' and get the users with their relevant company details . this is the user model: class User(db.Model): __tablename__ = 'user' id = db.Column(db.Integer, primary_key=True, autoincrement=True) firstname = db.Column(db.String(10), nullabl...
Malika
1

votes
1

answer
106

Views

hybrid attribute expression: aggregate attribute on many side of one to many

assuming these models: class A(Base): ... targets = relationship('B', back_populates='a') ... class B(Base): ... a_id = Column(Integer, ForeignKey('a.id')) a = relationship('A', back_populates='targets') attr = Column(ENUM('a', 'b', 'c', name='options'), default='a') ... How could I write a hybrid_a...
Verbal_Kint
0

votes
0

answer
2

Views

Not able to map two models in SqlAlchemy

I having two table models, one is a parent and another is child This is my parent model class users_table(Base): __tablename__ = 'users_table' userid = Column(String(50), unique= True, primary_key= True, nullable= False) username = Column(String(500), unique= True, nullable= False) password = Column...
Jithin Zacharia
0

votes
1

answer
14

Views

Why one thread can't not detect the changed value updated by the other thread? [duplicate]

This question already has an answer here: How to disable SQLAlchemy caching? 6 answers I am writing a program using SQLAlchemy, python, and multithreading. In my design, Thread A uses a while True loop. In each loop, it gets the queried object from database by SQLAlchemy, then check a field of the...
Cyan
1

votes
1

answer
520

Views

Two Columns joining the same table with SqlAlchemy

I'm building a sport related application in Flask using SqlAlchemy. I've got a Game table that has a home_team and an away_team which both join to the Team table. I want to be able to declare the relationship between the Team table and the Game table but I'm getting an error saying Could not determ...
hammygoonan
1

votes
2

answer
627

Views

sqlalchemy + flask: class is not defined

i'm using sqlalchemy + alembic + Flask and i can't map circular classes. apps/users/models.py: class User(Base): __tablename__ = 'users' id = Column(Integer, primary_key=True) email = Column(String) password = Column(String) session = relationship('Session', back_populates='user', cascade='all,dele...
1

votes
1

answer
1.4k

Views

Flask-SQLAlchemy Query records by relationship attribute

In the app I've been working on uses Flask-User and their suggested models for authorization control. Here's an example: class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) # User Authentication information username = db.Column(db.String(50), nullable=False, unique=True) pa...
1

votes
1

answer
767

Views

manually changing alembic's HEAD position

An alembic migration that I ran recently errored out prematurely for system-related reasons. I had to cancel out and complete the migration manually. Now alembic is insisting that the migration has not been run. I'd like to change the Alembic head position manually so that it believes that the migra...
jumbopap
1

votes
2

answer
1.2k

Views

sqlalchemy : Could not determine join condition between parent/child tables

I am very new to SQLAlchemy. I am having some difficulty setting up a one to many relationship between two models in my application. I have two models User `Photo'. A user has only one role associated with it and a role has many users associated with it. This is the code that I have in my data_gener...
pajarnas
2

votes
1

answer
24

Views

Why are they using .first here?

In my class they used the following code: pet = session.query(Pet).filter_by(name='Marshmallow').first() What does the .first() do here?
1

votes
2

answer
31

Views

Storing data values in multiple tables vs accessing the same value via query

I have designed my database tables where multiple tables store a value, all of which could be achieved via a query to one table. My question is would it be considered better practice to never store duplicate data and always query, or to store small values multiple times to reduce the number of queri...
aherzfeld
1

votes
1

answer
40

Views

Work on multiple branches with Flask-Migrate

I'm using Flask-Migrate (Alembic) to manage SQLAlchemy database migrations. I'm working on two different branches with different migrations. If I switch branches, I get an error that the migration is not found. If i merge this branches into the parent branch, I need downgrade migration's on both mu...
Anna
1

votes
0

answer
36

Views

Model example for make_declarative_base()

I've upgrade Flask-SQLalchemy from 2.1 and since 2.2 version this function requires a model parameter. Can somebody show an usage example for this?
Sht0p0r
1

votes
0

answer
273

Views

Transaction management using SQLAlchemy Core and Flask Python fails with Apache

Have a Flask web application with API calls and transaction management using SQLAlchemy Core. While inserting/updating into multiple tables simultaneously, the code excerpt that takes care of it: import os from sqlalchemy import create_engine DB_URL='postgresql://tasksys:[email protected]/mydb...
user956424
1

votes
2

answer
1.5k

Views

No module named sqlalchemy

I have tried using sudo easy_install sqlalchemy, pip install sqlalchemy and pip install flask-sqlalchemy. I have also tried installing and uninstalling sqlalchemy and flask. I get the error Traceback (most recent call last): File '/usr/lib/python2.7/multiprocessing/process.py', line 267, in _bootstr...
jc13
1

votes
0

answer
166

Views

InstrumentedAttribute vs Column in update() clause in SqlAlchemy

Given a simple ORM defined, class User(Base): __tablename__ = 'users' id = sql.Column(sql.Integer, primary_key=True) name = sql.Column(sql.String) What are the differences between the two approaches below to update a row? Approach 1 connection.execute( User.__table__.update() .where(User.name='Alic...
Pei
1

votes
1

answer
171

Views

How to ignore case when filter value in database with python [duplicate]

This question already has an answer here: Case Insensitive Flask-SQLAlchemy Query 2 answers I've tried to find an answer of my question. And I find some answers but I don't know how to apply those to my question. I'm using flask sqlalchemy. This is my python code for getting product list. def get_p...
Canet Robern
1

votes
0

answer
753

Views

Flask Countdown Timer without Sleep [duplicate]

This question already has an answer here: How many concurrent requests does a single Flask process receive? 4 answers Handle Flask requests concurrently with threaded=True 2 answers Display data streamed from a Flask view as it updates 1 answer I'm writing a web app with Flask and when I try to c...
user3246092
1

votes
1

answer
352

Views

how can I pass curent_user from flask-security to a pluggable view function?

I have a flask app that uses flask security for authentication. I want to use graphql with graphene to fetch data but I'm having trouble accessing the current_user proxy which is I've always used to resolve requests. graphene only provides a customized pluggable view which is understandable but it c...
Kasra Magmont
1

votes
1

answer
230

Views

SQLAlchemy scoped_session is not getting latest data from DB

I'm rather new to the whole ORM topic, and I've already searched forums and docs. The question is about a flask application with SQLAlchemy as ORM for the PostgreSQL. The __init__.py contains the following line: db = SQLAlchemy() the created object is referenced in the other files to access the DB....
SharedObject
1

votes
0

answer
477

Views

“Packet Sequence number wrong” when connecting with PyMySQL to MySQL running on vagrant

I am doing local development on a Flask application with MySQL set up to run on Vagrant. Using PyMySQL with SQLAlchemy, I'm connecting with mysql+pymysql://root:@127.0.0.1:2222/. When I run my application, I get the following error: sqlalchemy.exc.InternalError: (InternalError) Packet sequence numbe...
Spencer Carnage
1

votes
0

answer
53

Views

Using Flask-sqlalchemy, how to sort data using order_by with some avarage data which is need to join?

I am using flask-sqlalchemy to control Mysql as ORM. Here is my simple database graph simple graph about database Problem is that I am supposed to make a user list. Gonna sort each user based on the avarage star of reviews which can be found and calculated in many levels depth So I made some codes:...
Hustwhw
1

votes
0

answer
139

Views

Python Data Loading slow performance

I'm trying to read excel and bulk upload data to SQL Server Table. Data Loading works perfectly but it is taking longer than expected time. 28,000 record is taking 80 sec. I need to load 2-3 GB file in several occasions. I'm quite new to Python, Can you please take a look at the script and let me kn...
Partha
1

votes
1

answer
80

Views

Alternate preprocessing method to TypeDecorator in SQLAlchemy

I am using sqlalchemy.types.TypeDecorator to preprocess a text field before insertion into a database. It works great except when I am using the like expression with a comparator that contains percentages (e.g. User.name.like('%bar%')) because the percentages are stripped by the process_bind_param()...
slushy
1

votes
1

answer
65

Views

SQLAlcemy relationships that work with MySQL generate error when used with Sql Server

I have some SQLAlchemy ORM code working with MySQL but when I change the underlying database to Sql Server I get the message Module 'user_group' has no mapped classes registered under the name 'foreign_keys' Here's are the ORM definition of one of the primary classes: class User(Base): __tablename__...
Michael Ray Lovett
1

votes
0

answer
659

Views

Design patterns for flask API implementation

I am using flask with flask-restplus and sqlalchemy. My rest API function looks like the following: @ns.route('/user') class UsersCollection(Resource): @jwt_optional @permissions.user_has('admin_view') @ns.marshal_list_with(user_details) def get(self): ''' Returns list of users. ''' users = User.que...
Miro
1

votes
1

answer
1k

Views

pymysql.err.OperationalError: 2013 with pymysql and SQLAlchemy

guys! Hope someone can help me with this issue. I executing a query through SQLAlchemy that returns ~6kk rows (it's historical data) that I need to process on a python script. I have some functions to read and do some processing on the data using pandas dataframe.Here are the functions: def consulta...
aiquis
9

votes
2

answer
12.2k

Views

How to delete records from many-to-many (secondary) table in SQLAlchemy?

I am having problems deleting records from PostTag table that contains Post and Tag column. This is my relation table: tags = db.Table('PostTag', db.Column('Tag', db.Integer, db.ForeignKey('Tag.Id')), db.Column('Post', db.Integer, db.ForeignKey('Post.Id')) ) and tags = db.relationship(Tag, secondar...
pregmatch
1

votes
0

answer
63

Views

Using SqlAlchemy models in a long running process

I'm coming from a PHP & Doctrine ORM background. In doctrine orm, if I do a long running process like batch processing, it needs me to clear() the entity manager after processing some entities, to prevent 'ran out of memory' doctrine batch processing If I'm going to do something like below in pyth...
sanandrl
1

votes
1

answer
380

Views

Hot to set up permissions for GraphQL with graphene and SQLalchemy

I have Clients, Users, Projects and Trips on my graphene schema: class Clients(SQLAlchemyObjectType): class Meta: model = ClientModel interfaces = (relay.Node, ) class Users(SQLAlchemyObjectType): class Meta: model = UserModel interfaces = (relay.Node, ) class Projects(SQLAlchemyObjectType): class M...
Kevin Castro
1

votes
0

answer
296

Views

How to solve a sqlalchemy.exc.AmbiguousForeignKeysError in SQLalchemy?

I am learning SQLalchemy, so I decided to make a small database with a few tables in order to understand the way it works. In the docs and tutorials it all seems so clear, but when I start coding, I get long error messages, and right now I am stuck with this one. I am trying to create 3 related tab...
Victor Domingos
1

votes
0

answer
302

Views

Connecting to a remote DB via SSH for Flask [duplicate]

This question already has an answer here: MySQL connection over SSH tunnel - how to specify other MySQL server? 4 answers PostgreSQL via SSH Tunnel 1 answer I am using Flask,Flask-SQLAlchemy, and Postgres. I have set up the Postgres instance to allow local connection only i.e. can be accessed via...
Afeez Aziz
1

votes
0

answer
39

Views

How to select column from many-to-many table by SQLAlchemy

roles_users = db.Table('roles_users', db.Column('user_id', db.Integer(), db.ForeignKey('user.id')), db.Column('role_id', db.Integer(), db.ForeignKey('role.id')), db.Column('created_at', db.DateTime()) class Role(db.Model, RoleMixin): id = db.Column(db.Integer(), primary_key=True) name = db.Column(db...
Šimon Kostolný
1

votes
0

answer
24

Views

Blaze does not understand a SQLAlchemy type

I am getting errors trying to use blaze import pandas as pd import numpy as np from sqlalchemy import create_engine from blaze import * database_con = create_engine('mssql+pyodbc://server/database?driver=SQL Server Native Client 11.0', echo=False) bzdata = data(database_con) Blaze does not understan...
JOHN
1

votes
0

answer
173

Views

Custom migrations for PostgreSQL Materialized View with SQLAlchemy

I'm trying to auto-generate migrations for materialized views in SQLAlchemy, and the only thing that's not working is detecting changes between revisions. More specifically, it always generates a change, even when the model hasn't changed. I think the problem is, and I could just be using the wrong...
Brian
1

votes
0

answer
46

Views

Multiple relationships to the same SQLAlchemy model

I have a User table that has role column. role can be student, professor or admin. User table have relation with Course table. If relationship is between Course and student it should be many to many relation but if relationship is between Course and professor it should be one to many. How to defin...
Mehdi Sharifi
1

votes
1

answer
137

Views

SQLAlchemy relationship list for each row in query

MODELS: class Post(Base): id = Column(Integer, primary_key=True) ... topics = relationship('PostTopic', back_populates='post') class PostTopic(Base): post_id = Column(Integer, ForeignKey('post.id'), primary_key=True) topic_id = Column(Integer, ForeignKey('topic.id'), primary_key=True) topic = relat...
Yaniv Silberman
1

votes
0

answer
7

Views

How to access views, defined in postgresql using sqlalchemy ORM

I am attempting to read a view, defined in Postgresql as 'projects', that joins two tables: 'entity_registry' and 'project'. I have defined a class, 'Project', in python mapped to this view using sqlalchemy ORM constructs. The postgresql view is well formed as evidenced by the fact that it can be re...
Barry Huett
1

votes
0

answer
162

Views

sqlalchemy bulk insert, use add_all () and bulk_save_objects (),There are other better ways?

sqlalchemy bulk insert, use add_all () and bulk_save_objects (), which one should be better? There are other better ways? why?
xin.chen

View additional questions