flask-sqlalchemy

sqlalchemy join with sum and count of grouped rows

≯℡__Kan透↙ 提交于 2019-12-22 04:48:32
问题 Hi i am working on a little prediction game in flask with flask-sqlalchemy I have a User Model: class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) nick = db.Column(db.String(255), unique=True) bets = relationship('Bet', backref=backref("user")) and my Bet model class Bet(db.Model): id = db.Column(db.Integer, primary_key=True) uid = db.Column(db.Integer, db.ForeignKey('user.id')) matchid = db.Column(db.Integer, db.ForeignKey('match.id')) points = db.Column(db.Integer

TypeError: 'BaseQuery' object is not callable Flask [duplicate]

六月ゝ 毕业季﹏ 提交于 2019-12-22 04:33:33
问题 This question already has an answer here : Querying with function on Flask-SQLAlchemy model gives BaseQuery object is not callable error (1 answer) Closed last year . I am getting this error: TypeError: 'BaseQuery' object is not callable Here is my code: companies = Company.query.all() return Company.query(func.count(Company.id)) I need to find out number of rows in Company model. Please help! 回答1: Company.query isnt callable there. If you've already selected all your companies with companies

How can SQLAlchemy association_proxy be used bi-directionally?

六眼飞鱼酱① 提交于 2019-12-22 00:17:49
问题 I'm working with Flask-SQLAlchemy to create a many-to-many relationship using Association Objects and association_proxy , but I'm running into an issue: When I use association_proxy , I can set it up such that when I append a new instance to one side of the relationship, the Association Object will be created, but if I attempt to add an instance from the other side of the relationship, the Association Object constructor won't be passed the correct instance. Here's a simplified example where

flask-session: how to create the session table

旧时模样 提交于 2019-12-21 22:42:10
问题 I'm trying to enable server-side sessions for my flask application using a SQLite database. Note I'm using Flask-Sessionstore which is a hard fork of Flask-Session and is more actively maintained. However, I'm getting the same error when I use both libraries. Here is my code for app.py : from flask import Flask, session from flask_sqlalchemy import SQLAlchemy from flask_sessionstore import Session app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////Users/Johnny/DBs/test

flask sqlalchemy example around existing database

匆匆过客 提交于 2019-12-21 17:48:05
问题 Problem: there needs to be full working example of auto-mapping sqlalchemy to an existing database in an app with multiple binds. I want to bind to two databases and have one auto-map the tables. I need to do this because i don't have control over one DB, thus would have to constantly re-write my models and might delete new tables every time i migrate. I love the answers given here, but i can't seem to make it work in Flask (I am able to use the sqlalchemy only to query as per the example).

SQLAlchemy group_concat and duplicates

本小妞迷上赌 提交于 2019-12-21 09:29:00
问题 When I try to join a many-to-many table and group it by the main-id I am getting duplicates when I add the second many-to-many table. Here is how my models look like: Models user class User(UserMixin, db.Model): id = db.Column(db.Integer, primary_key=True) user_fistName = db.Column(db.String(64)) ... student_identifier student_identifier = db.Table('student_identifier', db.Column('class_id', db.Integer, db.ForeignKey('class.class_id')), db.Column('id', db.Integer, db.ForeignKey('user.id')) )

Flask-SQLAlchemy - When are the tables/databases created and destroyed?

醉酒当歌 提交于 2019-12-21 07:20:09
问题 I am a little confused with the topic alluded to in the title. So, when a Flask app is started, does the SQLAlchemy search the SQLALCHEMY_DATABASE_URI for the correct, in my case, MySQL database. Then, does it create the tables if they do not exist already? What if the database that is programmed into the SQLALCHEMY_DATABASE_URI variable in the config.py file does not exist? What if that database exists, and only a few of the tables exist (There are more tables coded into the SQLAlchemy code

SqlAlchemy won't accept datetime.datetime.now value in a DateTime column

限于喜欢 提交于 2019-12-21 07:08:38
问题 I should first mention that I'm using SqlAlchemy through Flask-SqlAlchemy. I don't believe this affects the issue but if it does, please let me know. Here is the relevant part of the error message I'm getting when running the create_all function in SqlAlchemy InterfaceError: (InterfaceError) Error binding parameter 4 - probably unsupported type. u'INSERT INTO podcasts (feed_url, title, url, last_updated, feed_data) VALUES (?, ?, ?, ?, ?)' (u'http://example.com/feed', u'Podcast Show Title', u

SqlAlchemy won't accept datetime.datetime.now value in a DateTime column

邮差的信 提交于 2019-12-21 07:08:06
问题 I should first mention that I'm using SqlAlchemy through Flask-SqlAlchemy. I don't believe this affects the issue but if it does, please let me know. Here is the relevant part of the error message I'm getting when running the create_all function in SqlAlchemy InterfaceError: (InterfaceError) Error binding parameter 4 - probably unsupported type. u'INSERT INTO podcasts (feed_url, title, url, last_updated, feed_data) VALUES (?, ?, ?, ?, ?)' (u'http://example.com/feed', u'Podcast Show Title', u

Setting a default role in flask-security

 ̄綄美尐妖づ 提交于 2019-12-21 06:20:42
问题 I am trying to set a default role when a user registers with my site, currently no roles are set when the user registers. I have created the roles I need, so I just need to define it somehow. Not sure how though. The code I have is pretty much copy paste from the quick start guide. Anyway, here it is: # Define models roles_users = db.Table('roles_users', db.Column('user_id', db.Integer(), db.ForeignKey('user.id')), db.Column('role_id', db.Integer(), db.ForeignKey('role.id'))) class Role(db