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

SQLAlchemy with_entities with dynamic inputs

how can I provide the with_entities option with dynamic input? At the moment I have to do this: columns = [DataModel.col1, DataModel.col2, ...] data = DataModel.query.order_by(DataModel.id.desc()).with_entities(*columns).first() But what should I…
meai2312
  • 167
  • 4
  • 12
2
votes
1 answer

How to properly select duplicate field names in a raw JOIN query in SQLAlchemy

I am tying to run a raw MySQL JOIN query using Connection.execute() in SQLAlchcemy. However, I am having trouble with getting the data of any two fields/columns with the same name. My models: class Client(db.Model): id = db.Column(db.Integer,…
M.Alsioufi
  • 565
  • 2
  • 7
  • 16
2
votes
1 answer

How use Postgre's HSTORE type in Flask application?

I'm a beginner in Flask & I tried to make one of my table column as HSTORE in my model. But I got an error. Can anyone point to me how I can use HSTORE type in flask app. I have checked too many links and can't find anything helpful for me. In…
Sarathlal N
  • 839
  • 5
  • 13
2
votes
0 answers

How to login using the test_client and use app_context of that login to issue a PUT request?

I am writing pytests for testing the API calls. First, I use the POST api to log the user in. Then I need to test a PUT api that allows the logged in user to edit profile info. The PUT api first checks whether g.current_user.id = id of the profile…
2
votes
1 answer

pymysql.err.OperationalError: (2013, 'Lost connection to MySQL server during query')

I had problems connecting to the heroku ClearDB with my flask-restful application, using SQLAlchemy with my given DB_URI: mysql+pymysql://username:password@remote-hostname-xx.cleardb.net/heroku_c52490fb3111cda?reconnect=true And this was the…
MattSom
  • 2,097
  • 5
  • 31
  • 53
2
votes
1 answer

Create a comment section in flask

Im working on the comment section of my page and found a useful website with this https://blog.miguelgrinberg.com/post/implementing-user-comments-with-sqlalchemy. The problem i am having is representing the comments on the website. How to i display…
High Roller
  • 67
  • 2
  • 16
2
votes
1 answer

SQLAlchemy utils drop database statement cannot be used inside a user transaction

I have the code below which fails with the message from sqlalchemy_utils.functions import database_exists, create_database, drop_database url = f'mssql+pymssql://user:secret_password@db_host/my_database?charset=utf8' if database_exists(url): …
s5s
  • 11,159
  • 21
  • 74
  • 121
2
votes
1 answer

WTForm - QuerySelectField doesn't take the given/default value from database. Flask - WTForms - Sqlalchemy

I use a wtform for both adding and editing an object and I use the queryselectfield for the foreign keys. The queryselectfield always takes the first value in the row. The correct value is actually passed right as far as I understand, it just…
2
votes
2 answers

SQLAlchemy: 'NoneType' object has no attribute 'drivername'

I'm trying to connect my flask application to my local MySQL database for testing. I've made a flask object and a class to represent an example table to be created after a successful connection. These are my local env vars for my…
MattSom
  • 2,097
  • 5
  • 31
  • 53
2
votes
1 answer

flask `Base query` object isn't callable?

I'm working on a project. when I set up flask-login system after that I'm getting error. Error: TypeError: 'BaseQuery' object is not callable when I remove flask-login system. It's working but I need to use. @login_manager.user_loader def…
Rohit Dalal
  • 135
  • 2
  • 9
2
votes
2 answers

Flask - SQLAlchemy - Add nullable=False column to existing table with data

I'm trying to add a new nullable=False column to an existing table. But it won't create the column because there are existing rows and the field is Null. It's a classic catch 22 :D. here's my model column I added: user_id = db.Column(db.Integer,…
ajbraus
  • 2,909
  • 3
  • 31
  • 45
2
votes
3 answers

TypeError: Column() got an unexpected keyword argument 'primary_key'

class Contacts(db.Model): """ sno, name, email, phone_num, msg, date """ sno = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(80), nullable=False) email = db.Column(db.String(20), nullable=False) …
rice
  • 53
  • 1
  • 6
2
votes
0 answers

1146 table doesn’t exist in flask python as it maps with wrong database

I tried to connect flask with two database(MySQL) one is Department and other one is Assign When I try to join the tables it shows errors that table Department.assigned doesn't exist. But assigned is mapped with Assign database. The below code I…
Sam
  • 41
  • 1
2
votes
0 answers

How can I change the default separator of group_concat() using SQLAlchemy?

I am trying to group_concat using SQLAlchemy. The problem is I want to change the separator from , to : ### code ##### ....... db.session.query(c1.ID,c1.cap ,func.group_concat(c1.Name.distinct(), ':' )).join(c2,(chart1.ID == c2.ID)).filter(c1.cap…
Sam
  • 41
  • 1
2
votes
1 answer

DB changes made in a Celery task not visible in the main thread

When updating or creating a new object in a Celery task, reading the new data in the main thread fails. After the update / create I issue db.session.commit() From cmd it seems that the data was updated in the DB, but maybe something with the…
Adi Ep
  • 509
  • 1
  • 5
  • 22