flask-sqlalchemy

Flask-SQLAlchemy Many to Many Insert

泄露秘密 提交于 2019-12-24 05:48:06
问题 Flask sqlalchemy many-to-many insert data I've tried the above advice but continue to recieve the following error on the append of a many to many attribute when inserting a new post with tags. Any direction would be most appreciated! 1:06:22 PM web.1 | post.tags.append(post_tag) 11:06:22 PM web.1 | File "/home/trevor/Projects/trevorblog/venv/local/lib/python2.7/site-packages/sqlalchemy/orm/collections.py", line 1072, in append 11:06:22 PM web.1 | item = __set(self, item, _sa_initiator) 11:06

How teardown_request() works with Python- Flask?

时间秒杀一切 提交于 2019-12-24 03:10:56
问题 I received internal error with message: "TimeoutError: QueuePool limit of size 5 overflow 10 reached, connection timed out, timeout 30" and searching online gave teardown_request() solution : @app.teardown_request def checkin_db(exc): try: print "Removing db session." db.session.remove() except AttributeError: pass Now timeout error is gone. But I didn't understand teardown_request completely, look like db.session.remove() will be invoked after every request ? or every error? Is it safe to

Flask Migrate using different postgres schemas ( __table_args__ = {'schema': 'test_schema']})

一个人想着一个人 提交于 2019-12-24 02:04:47
问题 I'm trying to use flask, sqlalchemy, and flask_migrate... But every time run manage.py migrate, alembic always detect my model as a new table. I think that i put table_args in my model to store table in a different postgres schema: class Entry(db.Model): __table_args__ = {'schema': app.config['BASE_SCH']} id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(100)) slug = db.Column(db.String(100), unique=True) body = db.Column(db.Text) status = db.Column(db.SmallInteger,

Flask-socketio context for Flask-SQLAlchemy

给你一囗甜甜゛ 提交于 2019-12-24 01:30:15
问题 I am creating a live reporting application using Flask, Flask-Socketio and Flask-SQLAlchemy. My current design creates a background thread on connection which querys an API and inserts into the applications data. However, when running this, I get the error RuntimeError: No application found. Either work inside a view function or push an application context. flask_react_app.py: from threading import Lock from flask import Blueprint, render_template from .model import Stock from . import

SQLAlchemy Truncating VARCHAR(MAX)

混江龙づ霸主 提交于 2019-12-24 00:17:52
问题 I'm querying Microsoft SQL Server 2008 with Flask-SQLAlchemy (.16) and SQL Alchemy (0.8.2) in python 2.7. When I attempt to query the varchar(max) column. It is truncating it to 4096 characters. I've tried different data types in the code. String, Text, VARCHAR. Any thoughts to get my code to pull all the data from my column? Here is part of the code: from web import db class DynamicPage(db.Model): __tablename__ = 'DynamicPage' DynamicPageId = db.Column(db.Integer, primary_key=True) PageHtml

How to use “Like” operator in sqlAlchemy [duplicate]

三世轮回 提交于 2019-12-23 17:25:32
问题 This question already has answers here : SQLAlchemy equivalent to SQL “LIKE” statement (4 answers) Closed 3 years ago . Hi I am a new member in stackoverflow. I am currently using sqlAlchemy in flask. Trying to get the matched categories of string provided with the search url. The code of search url is given below: @productapi.route("/search/category", methods=["GET"]) def search_category(): category_param_value = request.args.get('querystr', None) print(category_param_value) if category

Passing application context to custom converter using the Application Factory pattern

冷暖自知 提交于 2019-12-23 15:54:21
问题 I am currently building an application that uses the Application Factory pattern. In this application, I have a custom URL converter, that takes an integer and returns an SQLAlchemy model instance with that ID, if it exists. This works fine when I'm not using the Application Factory pattern, but with it, I get this error when accessing any route that uses the converter: RuntimeError: application not registered on db instance and no application bound to current context My application structure

Can't delete row from SQLAlchemy due to wrong session

℡╲_俬逩灬. 提交于 2019-12-23 12:13:24
问题 I am trying to delete an entry from my table. This is my code for the delete function. @app.route("/delete_link/<link_id>", methods=['GET', 'POST']) def delete_link(link_id): link = models.Link.query.filter(models.Link.l_id == link_id).first() db.session.delete(link) db.session.commit() return flask.redirect(flask.url_for('links')) the line: db.session.delete(link) returns me this error: InvalidRequestError: Object '' is already attached to session '1' (this is '2') I've tried this code as

Flask SQLAlchemy db.create_all() not creating database

老子叫甜甜 提交于 2019-12-23 09:56:35
问题 I can't seem to figure out why my call to db.create_all() is not working. I have an app package with following init: from flask import Flask from config import config from flask.ext.sqlalchemy import SQLAlchemy # create the database object db = SQLAlchemy() # this function is the application factory def create_app(environment): app = Flask(__name__) app.config.from_object(config[environment]) db.init_app(app) from bp_root import bp_root from bp_aws import bp_aws app.register_blueprint(bp_root

Flask SQLAlchemy db.create_all() not creating database

故事扮演 提交于 2019-12-23 09:55:26
问题 I can't seem to figure out why my call to db.create_all() is not working. I have an app package with following init: from flask import Flask from config import config from flask.ext.sqlalchemy import SQLAlchemy # create the database object db = SQLAlchemy() # this function is the application factory def create_app(environment): app = Flask(__name__) app.config.from_object(config[environment]) db.init_app(app) from bp_root import bp_root from bp_aws import bp_aws app.register_blueprint(bp_root