flask-sqlalchemy

SQLAlchemy inheritance not working

前提是你 提交于 2019-12-21 03:58:08
问题 I'm using Flask and SQLAlchemy. I have used my own abstract base class and inheritance. When I try to use my models in the python shell I get the following error: >>> from schedule.models import Task Traceback (most recent call last): File "<console>", line 1, in <module> File "/home/teelf/projects/schedule/server/schedule/models.py", line 14, in <module> class User(Base): File "/home/teelf/projects/schedule/server/venv/lib/python3.4/site-packages/flask_sqlalchemy/__init__.py", line 536, in _

Flask-SQLAlchemy: Can't reconnect until invalid transaction is rolled back

∥☆過路亽.° 提交于 2019-12-20 11:57:07
问题 So I am using Amazon Web Services RDS to run a MySQL server and using Python's Flask framework to run the application server and Flask-SQLAlchemy to interface with the RDS. My app config.py SQLALCHEMY_DATABASE_URI = '<RDS Host>' SQLALCHEMY_POOL_RECYCLE = 60 My __ init __.py from flask import Flask from flask.ext.sqlalchemy import SQLAlchemy application = Flask(__name__) application.config.from_object('config') db = SQLAlchemy(application) I have my main application.py from flask import Flask

Update row (SQLAlchemy) with data from marshmallow

十年热恋 提交于 2019-12-20 11:49:35
问题 I'm using Flask, Flask-SQLAlchemy, Flask-Marshmallow + marshmallow-sqlalchemy, trying to implement REST api PUT method. I haven't found any tutorial using SQLA and Marshmallow implementing update. Here is the code: class NodeSchema(ma.Schema): # ... class NodeAPI(MethodView): decorators = [login_required, ] model = Node def get_queryset(self): if g.user.is_admin: return self.model.query return self.model.query.filter(self.model.owner == g.user) def put(self, node_id): json_data = request.get

flask-sqlalchemy - PostgreSQL - Define specific schema for table?

会有一股神秘感。 提交于 2019-12-20 09:53:34
问题 I want to define a specific schema for a 'model' using flask-sqlalchemy. When you create a table object in sqlalchemy itself it has a parameter to pass for schema name. How do I do this in flask-sqlalchemy? 回答1: When you define your model class use: __table_args__ = {"schema":"schema_name"} maybe it will save someone else some hunting. 回答2: For future references: db = flask.ext.sqlalchemy.SQLAlchemy(app) app.config['SQLALCHEMY_DATABASE_URI'] = 'your_default_schema_db_uri' app.config[

How to insert timeseries data into SQLite using SQLalchemy?

∥☆過路亽.° 提交于 2019-12-20 06:37:38
问题 I am developing an app which obtains financial data from the Federal Reserve, stores it in a SQlite database using Flask-SQlalchemy, and then serves the data to my front-end dashboard (Bokeh). The data I am using is structured as follows: date realtime_end realtime_start value 0 1962-01-02 2018-08-02 2018-08-02 4.06 1 1962-01-03 2018-08-02 2018-08-02 4.03 2 1962-01-04 2018-08-02 2018-08-02 3.99 3 1962-01-05 2018-08-02 2018-08-02 4.02 4 1962-01-08 2018-08-02 2018-08-02 4.03 5 1962-01-09 2018

How to query many-to-many based on some constraints in flask sqlalchemy?

假装没事ソ 提交于 2019-12-20 06:23:43
问题 If I have a User and Item model, and they have a many-to-many association with each other, how do I build a query that returns: (1) All items that belong to any user named 'Bob' I tried: Item.query.filter(User.name == 'Bob') Which returns all items regardless of the user's name (incorrect) (2) All items that have the name 'shark' and belong to any user named 'Bob' I tried: Item.query.filter(User.name == 'Bob' & Item.name == 'shark') Same as above, but only returns items named 'shark'

SQLAlchemy with_for_update row locking not working?

安稳与你 提交于 2019-12-20 05:42:01
问题 There is a student whose type attribute is 4 and the minimum value for type attribute can be 1. In postgres In session 1, I exclusively lock and update a row in the student table: BEGIN; LOCK TABLE students IN ROW EXCLUSIVE MODE; SELECT * FROM students WHERE id = 122 FOR UPDATE; UPDATE students SET type = 1 WHERE id = 122; END; In session 2 I concurrently run: UPDATE students SET type = type - 1 WHERE id = 122; The result I get is an exception, i.e student's type can't be lower than 1 in

SQLAlchemy with_for_update row locking not working?

China☆狼群 提交于 2019-12-20 05:41:10
问题 There is a student whose type attribute is 4 and the minimum value for type attribute can be 1. In postgres In session 1, I exclusively lock and update a row in the student table: BEGIN; LOCK TABLE students IN ROW EXCLUSIVE MODE; SELECT * FROM students WHERE id = 122 FOR UPDATE; UPDATE students SET type = 1 WHERE id = 122; END; In session 2 I concurrently run: UPDATE students SET type = type - 1 WHERE id = 122; The result I get is an exception, i.e student's type can't be lower than 1 in

Flask-sqalchemy and oracle database id not autoincrement

半城伤御伤魂 提交于 2019-12-20 04:58:26
问题 I want to make a new table in my database (Oracle 11g but the Express Edition for Ubuntu 16.04) using Python and Flask framework with the SQLAlchemy module. The first field of the table it's and ID, is an Integer field and I want it to autoincrement, but Oracle database don't support the autoincrement. I have a form to add a new comment, but when I try to add a new record it reports a error: sqlalchemy.exc.IntegrityError: (cx_Oracle.IntegrityError) ORA-01400: cannot insert NULL into ("WIKTOR"

SQLAlchemy @property causes 'Unknown Field' error in Marshmallow with dump_only

痞子三分冷 提交于 2019-12-20 04:25:22
问题 I'm using flask-marshmallow (marshmallow=v3.0.0rc1, flask-marshmallow=0.9.0) and flask-sqlalchemy (sqlalchemy=1.2.16, flask-sqlalchemy=2.3.2) I have this model and schema. from marshmallow import post_load, fields from .datastore import sqla_database as db from .extensions import marshmallow as ma class Study(db.Model): _id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String, nullable=False) tests = db.relationship("Test", backref="study", lazy='select', cascade="all, delete