flask-sqlalchemy

'No application found. Either work inside a view function or push an application context.' [duplicate]

一个人想着一个人 提交于 2020-01-09 09:56:29
问题 This question already has answers here : creating a database outside the application context (3 answers) When scattering Flask Models, RuntimeError: 'application not registered on db' was raised (2 answers) Closed 2 years ago . I'm trying to separate my Flask-SQLAlchemy models into separate files. When I try to run db.create_all() I get No application found. Either work inside a view function or push an application context. shared/db.py : from flask_sqlalchemy import SQLAlchemy db =

Remove duplicates from QuerySelectField

£可爱£侵袭症+ 提交于 2020-01-06 07:53:34
问题 i'm running into issues with the following, and I'm wondering if it is even possible. I have a flask-admin adminview setup, with an extra form field which shows a dropdown based on a specific column (category) in the sql model. See code for clarification: model: class Item(db.Model): id = db.Column(db.Integer, primary_key = True) name = db.Column(db.String(128), index = True) category = db.Column(db.String(16)) I have the extra form field in Flask-Admin as follows: form_extra_fields = {

Flask-SQLAlchemy session object not seeing changes to the database?

自古美人都是妖i 提交于 2020-01-06 05:47:08
问题 I have a website on PythonAnywhere that uses Flask and Flask-SQLAlchemy connected to a MySQL database. Users can use the website to queue a task that is saved to the database as a record in a table, and then a separate scheduled task (Python program) checks the database and handles every unhandled record. The problem I'm encountering is that the scheduled task's db query seems to only find new records when it runs for the first time, but if I then use the website to add a new task, the still

Inappropriate datetime datatype and error on Flask App

旧巷老猫 提交于 2020-01-06 05:16:06
问题 Background What I would like to do is to implement a form to insert datetime with the specific data type (like 2019-10-23 22:38:18) on a web application written in Python Flask and SQLAlchemy. complete image id | name | city | datetime ----+--------+---------+--------- 1 | Hans | London |2019-10-23 22:37:10 2 | John | NewYork |2019-10-23 22:38:18 database List of relations Schema | Name | Type | Owner --------+-------+-------+------- public | todos | table | username Problem I've checked that

How to build a URL with commas to query with filters using flask-wtforms jinja QuerySelectField and python operators “eq,gt,lt,et”

情到浓时终转凉″ 提交于 2020-01-06 04:45:09
问题 This is a flask front end to an Accounting database. I am struggling to create a form to pass a query back to veiw function, I need to query one or more columns out of eleven columns at once, I have the code for the backend side after somebody helped me here but I dont know how to build a URL like this: books?filter=aux,eq,FILCUI&credit,eq,445663 where eq are operators from here. These I can use as a dropdown list to have "eqaul too" "greater than" "not eqaul". Brilliant Six of my eleven

Accessing table variables in Flask-Sqlalchemy query during search

匆匆过客 提交于 2020-01-06 03:48:03
问题 I am writing a RESTful api using Flask and Flask-SQLalchemy, as well as Flask-Login. I have a model Users that's initialized like: class Users(UserMixin, db.Model): __tablename__ = "users" # STATIC Standard required info id = db.Column("id", db.Integer, primary_key = True) public_id = db.Column("public_id", db.String(50), unique = True) email = db.Column("email", db.String(50), unique = True) username = db.Column("username", db.String(20), unique = True) password = db.Column("password", db

Automatically setting the value of a field based on another with SQLAlchemy

孤人 提交于 2020-01-06 02:46:06
问题 Using Flask-SQLAlchemy I have a table which looks like this: class User(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(100), nullable=False) slug = db.Column(db.String(200), nullable=False) def __init__(self, name): self.name = name I have a Python library which converts the value of some text into a slug like slugify('Hello World') to hello-world . Say I was to create a User: user = User('John Smith') db.session.add(user) db.session.commit() I would like

How to nest conjunctions or_ and and_ in SQLAlchamey

﹥>﹥吖頭↗ 提交于 2020-01-05 08:10:52
问题 I'm tyring to recreate this query in SQL Alchamey but I've been unable to nest the filters: Query: SELECT * FROM calendar where (recurrenceRule = '') or (recurrenceRule != '' and start < @end1); Python: events.filter(or_(Calendar.recurrenceRule!='', (Calendar.recurrenceRule=='',Calendar.start>=filterStart)) This python results in the following exception: "SQL expression object or string expected." 回答1: You must use and_ explicitly: events.filter(or_( Calendar.recurrenceRule!='', and_(Calendar

How do I search for dates registered as an array in Json?

自古美人都是妖i 提交于 2020-01-05 07:09:10
问题 How do I search for dates registered as an array in Json? (PostgreSQL is DB.) Below is the relevant code. ##### 1. Model ##### class Business(db.Model): __tablename__ = 'business' id = db.Column(db.Integer, primary_key=True) sales = db.Column(JSON) ##### 2. Data ##### id=1 sales={'time': ['10:00', '19:00']}, ##### 3. View Query ##### # filter var filter_val = request.json['filter']['value'] # basic query bQuery = Business.query # Filter query if filter_val['sales']['time'][0]: bQuery = bQuery

why the stored procedure called from sqlalchemy is not working but calling from workbench is working?

半城伤御伤魂 提交于 2020-01-05 05:45:12
问题 I have a stored procedure. calling it via MySQL workbench as follows working; CALL `lobdcapi`.`escalatelobalarm`('A0001'); But not from the python program. (means it is not throwing any exception, process finish execution silently) if I make any error in column names, then at python I get an error. So it calls my stored procedure but not working as expected. (it is an update query .it needs SAFE update ) Why through the python sqlalchemy this update didn't update any records? CREATE DEFINER=