Questions tagged [flask-sqlalchemy]

Flask-SQLALchemy is an extension for Flask that provides SQLAlchemy support. It is designed to make database manipulation through SQLAlchemy even easier and simpler. It has the same three clause BSD License as Flask.

Armin Ronacher has developed Flask-SQLAlchemy as well as Flask itself, Jinja and Werkzeug. All of those written in Python. In the extension project main page the autor states:

Flask-SQLAlchemy is an extension for Flask that adds support for SQLAlchemy to your application. It aims to simplify using SQLAlchemy with Flask by providing useful defaults and extra helpers that make it easier to accomplish common tasks.

Flask-SQLAlchemy is open-source and hosted on Github

It's easy to setup and easier to use. You just have to install it via pip install Flask-SQLAlchemy or easy_install Flask-SQLAlchemy, and have the required software already installed.

After that you can test the installation and get a grasp of the basic usage with this quickstart tutorial.

7021 questions
2
votes
1 answer

Update a sqlalchemy association proxy target when updating the parent ORM table

I have a Flask SQLAlchemy project with 3 ORM tables, Category, Vendor, and CategoryVendorMap, and I am using Flask-Marshmallow to define schemas for the api. Relationships: Category has many Vendors by way of CategoryVendorMap. CategoryVendorMap…
steve
  • 2,488
  • 5
  • 26
  • 39
2
votes
0 answers

DISTINCT ON in subquery by SQLAlchemy

I have a problem with query by ORM SQLAlchemy. I need to write subquery like this SELECT DISTINCT ON (e.type) e.type AS e_type, e.num AS e_num FROM e ORDER BY e.type by ORM SQLAlchemy, but when I've used .subquery().alias("q") in my query,…
2
votes
1 answer

How to use the order_by defined on the relationship in SQLAlchemy and contains_eager?

The Zen of Joined Eager Loading docs recommends using contains_eager() if we want to keep the relationship order defined in the model. "If we wanted to use just one JOIN for collection loading as well as ordering, we use the contains_eager()…
Tudor
  • 4,137
  • 5
  • 38
  • 54
2
votes
0 answers

Automatically populate a table defined by a sqlalchemy class based on two other classes/tables

I am building a flask application and using flask-sqlalchemy. I have two classes defined as follows: class RawMaterials(db.Model): __tablename__ = 'rawMaterials' id = db.Column(db.Integer, autoincrement=True) stockCode =…
Kartikeya Sharma
  • 1,335
  • 1
  • 10
  • 22
2
votes
0 answers

How can I set timestamp precision with SQLAlchemy and Postgresql

I’m using flask-sqlalchemy with postgresql database. I have some Columns with timestamps. I'm setting them like this: class Return_attempt(db.Model): ''' Data related with each return attempt''' time_waiting_collection = \ …
2
votes
1 answer

Different type of user registration in flask

I am new in Flask and I just wanted to create a simple market place with it. There are three type of users [sellers, buyers, admins] in my website. I think each type of users should have it's own registration and login because due to their role…
smhquery
  • 98
  • 6
2
votes
1 answer

TypeError: can only concatenate list (not "str") to list | Alembic Migration

I am trying to run a migration to add a foreign key constraint. This is when I try to add a artist_id to my RSVP model on a many to one relationship. Each RSVP can only have an artist, and an artist can have many rsvps. Here is my migration code def…
2
votes
1 answer

How to order child records by parent column using flask-sqlalchemy?

class Parent(db.Model): id = db.Column(db.Integer, primary_key=True) role_id = db.Column(db.Integer, db.ForeignKey('role.id') name = db.Column(db.String()) children = db.relationship('Child', backref='parent') class…
Jitendra
  • 461
  • 6
  • 15
2
votes
0 answers

flask-sqlalchemy rollback best practices

I am trying to find some clarity on the best practices for where in a flask application database errors should best be handled and rollback should be performed. I have looked through the SQLAlchemy docs and I have not found any recommendations on…
2
votes
2 answers

How to show flask foreign key field in modelform with readable display dropdown?

I have a one to many and many to many relationship in my models. I'm using wtforms_alchemy ModelForm to create the forms, but the ForeignKey field is not showing up as a drop down field, also it's showing the integers as values in them. I tried…
2
votes
1 answer

SQLAlchemy: code a unit test for a model class with circular relationship

I'm trying to code a unit test of my UserModel class which is the next: from db import db from logs import Logger class UserModel(db.Model): __tablename__ = 'users' id = db.Column(db.Integer, primary_key=True) email =…
Adrian
  • 343
  • 2
  • 15
2
votes
0 answers

Having error at db.session.add when I tried to execute function using apscheduler

I implemented API in Flask and working correctly. (Get some data from other API endpoint and store into database) I also want to call this API as a cron job. Thus, I am using apscheduler to execute the function for API but got following error. Could…
Katsuya Obara
  • 903
  • 3
  • 14
  • 30
2
votes
0 answers

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 query to that searches in the first element of all…
robscott
  • 91
  • 7
2
votes
1 answer

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 have a User table with authentication data and I…
2
votes
0 answers

import data from source db to target db using flask sqlalchemy

I want to fetch data from one source database and insert it into my targeted database using flask SQL alchemy Database_connection app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:root@localhost/store' app.config['SQLALCHEMY_BINDS'] =…