flask-sqlalchemy

sqlalchemy hybrid_attribute expression

我们两清 提交于 2021-02-11 13:23:25
问题 Assuming the following models: class Worker(Model): __tablename__ = 'workers' ... jobs = relationship('Job', back_populates='worker', order_by='desc(Job.started)', lazy='dynamic') @hybrid_property def latest_job(self): return self.jobs.first() # jobs already ordered descending @latest_job.expression def latest_job(cls): Job = db.Model._decl_class_registry.get('Job') return select([func.max(Job.started)]).where(cls.id == Job.worker_id).as_scalar() class Job(Model): ... started = db.Column(db

Flask app gives a “ 'NoneType' object has no attribute 'drivername' ” error

筅森魡賤 提交于 2021-02-10 14:20:01
问题 I got a VPS and I wanted to host my flask app there. I followed DigitalOcean's tutorial on "How To Serve Flask Applications with Gunicorn and Nginx on Ubuntu 18.04" (I didnt get the VPS from DO) and everything worked fine with the example app... when I tried to replace the files with my app's files and host the app again I get a 500 error. The 500 error doesnt appear everywhere. It comes up where my .db file is envoled like where I have posts or users etc.. Everything else loads up fine. The

Flask app gives a “ 'NoneType' object has no attribute 'drivername' ” error

点点圈 提交于 2021-02-10 14:15:40
问题 I got a VPS and I wanted to host my flask app there. I followed DigitalOcean's tutorial on "How To Serve Flask Applications with Gunicorn and Nginx on Ubuntu 18.04" (I didnt get the VPS from DO) and everything worked fine with the example app... when I tried to replace the files with my app's files and host the app again I get a 500 error. The 500 error doesnt appear everywhere. It comes up where my .db file is envoled like where I have posts or users etc.. Everything else loads up fine. The

Flask-migrate: change model attributes and rename corresponding database columns

折月煮酒 提交于 2021-02-10 12:38:07
问题 I have a bit of experience with Flask but not very much with databases (Flask-migrate / alembic / SqlAlchemy). I'm following this tutorial and things are working quite alright. I have a User model like this: # user_model.py from app import DB ... other imports class User(UserMixin, DB.Model): __tablename__ = 'users' id = DB.Column(DB.Integer, primary_key=True) username = DB.Column(DB.String(64), index=True, unique=True) email = DB.Column(DB.String(120), index=True, unique=True) password_hash

Flask-migrate: change model attributes and rename corresponding database columns

给你一囗甜甜゛ 提交于 2021-02-10 12:37:06
问题 I have a bit of experience with Flask but not very much with databases (Flask-migrate / alembic / SqlAlchemy). I'm following this tutorial and things are working quite alright. I have a User model like this: # user_model.py from app import DB ... other imports class User(UserMixin, DB.Model): __tablename__ = 'users' id = DB.Column(DB.Integer, primary_key=True) username = DB.Column(DB.String(64), index=True, unique=True) email = DB.Column(DB.String(120), index=True, unique=True) password_hash

Can I execute query via sqlalchemy without transaction

非 Y 不嫁゛ 提交于 2021-02-09 18:02:49
问题 I am trying to execute a stored procedure on Mysql database with sqlalchemy. It runs fine from the shell but throws this error: OperationalError: (MySQLdb._exceptions.OperationalError) (1568, "Transaction characteristics can't be changed while a transaction is in progress") The reason as it seems is that SQLAlchemy runs query within a transaction. And the transaction within the stored procedure is conflicting with it. Below is sqlalchemy log: 2019-07-24 15:20:28,888 INFO sqlalchemy.engine

Can I execute query via sqlalchemy without transaction

别等时光非礼了梦想. 提交于 2021-02-09 18:02:25
问题 I am trying to execute a stored procedure on Mysql database with sqlalchemy. It runs fine from the shell but throws this error: OperationalError: (MySQLdb._exceptions.OperationalError) (1568, "Transaction characteristics can't be changed while a transaction is in progress") The reason as it seems is that SQLAlchemy runs query within a transaction. And the transaction within the stored procedure is conflicting with it. Below is sqlalchemy log: 2019-07-24 15:20:28,888 INFO sqlalchemy.engine

Can I execute query via sqlalchemy without transaction

和自甴很熟 提交于 2021-02-09 18:01:22
问题 I am trying to execute a stored procedure on Mysql database with sqlalchemy. It runs fine from the shell but throws this error: OperationalError: (MySQLdb._exceptions.OperationalError) (1568, "Transaction characteristics can't be changed while a transaction is in progress") The reason as it seems is that SQLAlchemy runs query within a transaction. And the transaction within the stored procedure is conflicting with it. Below is sqlalchemy log: 2019-07-24 15:20:28,888 INFO sqlalchemy.engine

How can I initialize the database automatically with SQLalchemy and Alembic?

心不动则不痛 提交于 2021-02-09 08:48:09
问题 Currently, I run $ flask db init $ flask db migrate -m "initialization" $ flask db upgrade if the database does not exist. I would like to run this within Python, e.g. something like app.create_db() so that I don't have to care about setting the database up. Is that possible? I use the flask-sqlalchemy and flask-migrations plugins 回答1: Obviously, you have installed flask-migrate, flask-sqlalchemy . So, you can do like this: from flask_sqlalchemy import SQLAlchemy from flask import Flask app =

What is correct way to use Flask-SQLAlchemy in Flask server?

回眸只為那壹抹淺笑 提交于 2021-02-08 11:39:40
问题 This is model code, I have tested this code, it is no error and it can create tables, records in DB createdb.py app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:@localhost:3306/ai' db = SQLAlchemy(app) if __name__ == 'createdb': db.reflect() db.drop_all() db = SQLAlchemy(app) class Class(db.Model): id = db.Column(db.Integer, primary_key=True, unique=True, autoincrement=True) label = db.Column(db.String(255), unique=True, nullable=False) def __init__(self,