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.

6057 questions
258
votes
9 answers

How to execute raw SQL in Flask-SQLAlchemy app

How do you execute raw SQL in SQLAlchemy? I have a python web app that runs on flask and interfaces to the database through SQLAlchemy. I need a way to run the raw SQL. The query involves multiple table joins along with Inline views. I've…
starwing123
  • 2,693
  • 2
  • 11
  • 7
174
votes
5 answers

How to update SQLAlchemy row entry?

Assume table has three columns: username, password and no_of_logins. When user tries to login, it's checked for an entry with a query like user = User.query.filter_by(username=form.username.data).first() If password matches, he proceeds further.…
webminal.org
  • 37,814
  • 34
  • 84
  • 122
169
votes
4 answers

How to delete a record by id in Flask-SQLAlchemy

I have users table in my MySql database. This table has id, name and age fields. How can I delete some record by id? Now I use the following code: user = User.query.get(id) db.session.delete(user) db.session.commit() But I don't want to make any…
Sergey
  • 4,676
  • 3
  • 21
  • 36
161
votes
5 answers

How do I know if I can disable SQLALCHEMY_TRACK_MODIFICATIONS?

Every time I run my app that uses Flask-SQLAlchemy I get the following warning that the SQLALCHEMY_TRACK_MODIFICATIONS option will be disabled. /home/david/.virtualenvs/flask-sqlalchemy/lib/python3.5/site-packages/flask_sqlalchemy/__init__.py:800:…
Robert
  • 33,260
  • 14
  • 84
  • 130
153
votes
8 answers

Flask SQLAlchemy query, specify column names

How do I specify the column that I want in my query using a model (it selects all columns by default)? I know how to do this with the sqlalchmey session: session.query(self.col1), but how do I do it with with models? I can't do SomeModel.query().…
Matthew Scragg
  • 3,886
  • 3
  • 17
  • 26
147
votes
5 answers

Flask-SQLalchemy update a row's information

How can I update a row's information? For example I'd like to alter the name column of the row that has the id 5.
pocorschi
  • 3,225
  • 5
  • 23
  • 35
131
votes
15 answers

jsonify a SQLAlchemy result set in Flask

I'm trying to jsonify a SQLAlchemy result set in Flask/Python. The Flask mailing list suggested the following method http://librelist.com/browser//flask/2011/2/16/jsonify-sqlalchemy-pagination-collection-result/#04a0754b63387f87e59dda564bde426e…
mal-wan
  • 4,111
  • 4
  • 22
  • 36
128
votes
7 answers

SQLAlchemy ORM conversion to pandas DataFrame

Is there a solution converting a SQLAlchemy to a pandas DataFrame? Pandas has the capability to use pandas.read_sql but this requires use of raw SQL. I have two reasons for wanting to avoid it: I already have everything using the ORM…
Jared
  • 2,713
  • 10
  • 31
  • 59
127
votes
2 answers

Flask-SQLAlchemy import/context issue

I want to structure my Flask app something like: ./site.py ./apps/members/__init__.py ./apps/members/models.py apps.members is a Flask Blueprint. Now, in order to create the model classes I need to have a hold of the app, something like: #…
Brad Wright
  • 4,692
  • 6
  • 27
  • 29
113
votes
6 answers

flask-sqlalchemy or sqlalchemy

I am new in both flask and sqlalchemy, I just start working on a flask app, and I am using sqlalchemy for now. I was wondering if there is any significant benefit I can get from using flask-sqlalchemy vs sqlalchemy. I could not find enough…
Amin
  • 1,535
  • 4
  • 15
  • 20
110
votes
3 answers

Flask-SQLAlchemy how to delete all rows in a single table

How do I delete all rows in a single table using Flask-SQLAlchemy? Looking for something like this: >>> users = models.User.query.all() >>> models.db.session.delete(users) # but it errs out: UnmappedInstanceError: Class '__builtin__.list' is not…
SeanPlusPlus
  • 6,800
  • 14
  • 52
  • 74
105
votes
3 answers

Case Insensitive Flask-SQLAlchemy Query

I'm using Flask-SQLAlchemy to query from a database of users; however, while user = models.User.query.filter_by(username="ganye").first() will return doing user =…
Ganye
  • 1,891
  • 3
  • 14
  • 13
94
votes
1 answer

What is the difference between the declarative_base() and db.Model?

The quickstart tutorial for the Flask-SQLAlchemy plugin instructs users to create table models inheriting the db.Model class, e.g. app = Flask(__main__) db = SQLAlchemy(app) class Users(db.Model): __tablename__ = 'users' ... However, the…
drs
  • 4,828
  • 3
  • 33
  • 59
85
votes
3 answers

Flask sqlalchemy many-to-many insert data

I am trying to make a many to many relation here in Flask-SQLAlchemy, but it seems that I don't know how to fill the "many to many identifier database". Could you please help me understand what I am doing wrong and how it is supposed to look? class…
Sigils
  • 2,073
  • 4
  • 20
  • 32
76
votes
3 answers

Flask Download a File

I'm trying to create a web app with Flask that lets a user upload a file and serve them to another user. Right now, I can upload the file to the upload_folder correctly. But I can't seem to find a way to let the user download it back. I'm storing…
Saimu
  • 864
  • 1
  • 6
  • 9
1
2 3
99 100