flask-sqlalchemy

ImportError: cannot import name 'db' from 'database_functions'

ImportError: cannot import name 'db' from 'database_functions' Question: I’m trying to connect to a Postgres database using Flask and SQLAlchemy. I followed an youtube tutorial however it doesn’t seem to work for me, as it throws an error normally associated with circular dependencies. When i type on the Python console: from database_functions import db it …

Total answers: 1

How to access the content of a single column from a flask-sqlalchemy model?

How to access the content of a single column from a flask-sqlalchemy model? Question: I am new to flask, and I have a query pertaining flask-sqlalchemy. My program makes use of dropzone.js and so it uploads multiple images and the goal is to save the image-file urls as string list to database for access later. …

Total answers: 1

Flask-SQLAlchemy raises TypeError: Query.paginate() takes 1 positional argument but 4 were given

Flask-SQLAlchemy raises TypeError: Query.paginate() takes 1 positional argument but 4 were given Question: I call Flask-SQLAlchemy’s query.paginate method with arguments. Recently this stopped working and instead raised a TypeError. How do I pass page and other arguments to query.paginate? Ticker.query.paginate(page, app.config["TICKERS_PER_PAGE"], False) TypeError: Query.paginate() takes 1 positional argument but 4 were given Asked By: Søren …

Total answers: 1

How can I reuse and SQLAlchemy filter?

How can I reuse a SQLAlchemy filter? Question: I have a class which interacts with the SQLAlchemy objects through various methods and it issues queries for various tasks. Some of these queries use the same filter for example: def get_all_expired(self,my_model): q = session.query(my_model).filter( my_model.status == ‘OK’, my_model.is_validated == True, my_model.expires_at <= plum_dt.now(), ) return q.all() …

Total answers: 2

sqlalchemy.create_all() got an unexpected keyword argument 'app' error

sqlalchemy.create_all() got an unexpected keyword argument 'app' error Question: new to coding, ive been stuck with this problem for about 4 days now and i have no idea how to get around it, ill paste the coding below init.py from flask import Flask from flask_sqlalchemy import SQLAlchemy from os import path from flask_login import LoginManager …

Total answers: 1

Flask-SQLAlchemy db.create_all() got an unexpected keyword argument 'app'

Flask-SQLAlchemy db.create_all() got an unexpected keyword argument 'app' Question: I’m following a tutorial for creating a Flask app with Flask-SQLAlchemy. However, it has started raising an error when creating the database. How do I create the database? from flask import Flask from flask_sqlalchemy import SQLAlchemy db = SQLAlchemy() def create_app(): app = Flask(__name__) app.config["SQLALCHEMY_DATABASE_URI"] = …

Total answers: 2

Flask-SQLAlchemy db.create_all() raises RuntimeError working outside of application context

Flask-SQLAlchemy db.create_all() raises RuntimeError working outside of application context Question: I recently updated Flask-SQLAlchemy, and now db.create_all is raising RuntimeError: working outside of application context. How do I call create_all? from flask import Flask from flask_sqlalchemy import SQLAlchemy app = Flask(__name__) app.config[‘SQLALCHEMY_DATABASE_URI’] = ‘sqlite:///project.db’ db = SQLAlchemy(app) class User(db.Model): id = db.Column(db.Integer, primary_key=True) db.create_all() This …

Total answers: 3

Flask SQLAlchemy,Postman returns a single data

Flask SQLAlchemy,Postman returns a single data Question: When ı run this code in VSCode: table_name = ‘student’ query = f’SELECT * FROM {table_name}’ result = db.session.execute(query) for elem in result: print(dict(elem)) It prints every data in the table. But when I try it in Postman with return and GET method: table_name = ‘student’ query = …

Total answers: 1

Flask-sqlalchemy check if data already exits in table before Inserting

Flask-sqlalchemy check if data already exits in table before Inserting Question: I am trying to insert some values into table using flask sqllite methods but I am not sure how to make the statement equivalent to Insert into table if not exits , the below method adds the data but if already present I want …

Total answers: 1