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

Flask-SQLAlchemy update one-to-many record

I have one-to-many relationship models, and here is the snippet of my models: class ScheduleDayAndTime(db.Model): __tablename__ = 'schedule_day_and_time' id = db.Column(db.Integer, primary_key=True) day = db.Column(db.Enum(DayNameList,…
Tri
  • 2,722
  • 5
  • 36
  • 65
2
votes
1 answer

Getting Error : 'ERROR [root] Error: No support for ALTER of constraints in SQLite dialect' while running 'flask db upgrade'

I have a flask application running with Sql Alchemy. Recently I have modified a table. And did it again. Initially it was working fine. But when I tried to migrate the db with command : flask db migrate I am getting error as : ERROR [root] Error:…
2
votes
1 answer

How to update on Flask-SQLAlchemy association table?

I have a models like this: taught_courses = db.Table( 'taught_courses', db.Column('teacher_id', db.Integer(), db.ForeignKey('teacher.id')), db.Column('course_id', db.Integer(), db.ForeignKey('course.id')), ) class Teacher(db.Model): …
Tri
  • 2,722
  • 5
  • 36
  • 65
2
votes
1 answer

Circular dependency while importing models for create_all() in a Flask App

Context: Python 3.6 flask flask_restful flask_sqlalchemy Objective: Create database tables before the first request to the flask restful api, avoiding circular dependency between models. Problem: When I do the first resquest,…
Carlos Ost
  • 492
  • 7
  • 22
2
votes
1 answer

Flask Pagenation returns only one column of data error python

I am having 1000s of data in MySQL. I am using flask Pagenation support to retrieve the data regarding the Page Number i gave. But it returns only one column of data. I have five columns of data in MySQL. I want know how to retrive all the data…
cheeze yes
  • 95
  • 1
  • 8
2
votes
1 answer

In my simple flask app, I'm unable to import classes from models.py. Circular import?

I'm trying to import a class from my models.py, but I think I'm running into a circular import issue. I'm not sure how to resolve this. I've tried moving the import, and changing imports in each file. app.py: from flask import Flask from…
rjb
  • 29
  • 1
2
votes
1 answer

Flask-Migrate creates the same duplicate migration when used with postgres schemas

I have a very simple and silly problem but I don't know what I'm missing. Basically, the way I've currently written my manage app, it seems flask migrate always creates an absolute migration and not just a change-set to migrate from the previous…
s5s
  • 11,159
  • 21
  • 74
  • 121
2
votes
1 answer

Using rank().over() function in flask-sqlalchemy returns (sqlite3.OperationalError) near "(": syntax error

I am using flask-sqlalchemy to perform a ranking query on a PlayerKillData table, which has 4 columns: ref_id (Primary Key), kill, all_kill and lvl. Specifically, what I want to achieve is to Rank by kill for player on the same lvl and add a Rank…
ksming
  • 1,422
  • 1
  • 16
  • 26
2
votes
0 answers

Add custom delete behavior to some objects with SQLAlchemy

I'd like to add some custom behavior to some SQLALchemy models when they are deleted, e.g. when a User is deleted, all his Posts are deleted too (easy to do using cascade), but I'd like to call a custom routine on each of those Posts when they are…
regu
  • 55
  • 8
2
votes
2 answers

SqlAlchemy : I want to filter query on 2 foreign keys

I have 2 tables (say Student and College) and a third table, which has student_id and college_id foreign keys. I don't want to hard delete Student and College rows, so I have included a deleted(Boolean) column in both tables. I want to add a student…
Shraddha
  • 154
  • 1
  • 11
2
votes
1 answer

How to use sqlite json1 features such as json_extract, json_each, json_tree using ORM DB API of flask-sqlalchemy?

I want to use json_extract, json_tree, json_each features of JSON1 Extension enabled sqlite3 database with flask-sqlalchemy. With reference to link here, I am making ORM query as below: Model class EventHistory(db.Model): timestamp =…
2
votes
1 answer

Dealing with Arrays in Flask-SqlAlchemy and MySQL

I have a datamodel where I store a list of values separated by comma (1,2,3,4,5...). In my code, in order to work with arrays instead of string, I have defined the model like this one: class MyModel(db.Model): pk = db.Column(db.Integer,…
Curro
  • 1,331
  • 1
  • 13
  • 24
2
votes
2 answers

Flask-SQLALchemy update record automatically after specific time

I have a db models like this: class Payment(db.Model): id = db.Column(db.Integer(), primary_key=True) user_id = db.Column(db.Integer(), db.ForeignKey('user.id')) ticket_status = db.Column(db.Enum(TicketStatus, name='ticket_status',…
Tri
  • 2,722
  • 5
  • 36
  • 65
2
votes
0 answers

How to paginate with flask usingquery with sessionmaker

This is a simple exercice, following instructions below, i need to paginate with sqlalchemy using sessionmaker... This is the main.py: from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker from database_config import…
Medinho
  • 193
  • 1
  • 3
  • 10
2
votes
1 answer

How to delete many-to-many association where uselist=True

In my application, instances of Parent share a one-to-many relationship with instances of Child. Each Parent may have many children, but each Child may have only one Parent. I understand how this relationship works. One important feature is that…
Matt Davis
  • 462
  • 1
  • 7
  • 10