sqlalchemy

AttributeError: type object 'User' has no attribute '_query_cls'

别等时光非礼了梦想. 提交于 2021-02-17 06:56:36
问题 User.id was of type postgresql.UUID Message.sender_id was of type postgresql.UUID with foreignkey to User.id . Changed my type to sqlalchemy_util.UUIDType . I had a problem for serializing my foreign key so I set my own JSONEncoder Now everything is working properly except when creating a Message (other classes with the same configuration does not have the problem). test_message.py def test_create_message(client, db, admin_user, admin_headers): # test bad data data = { 'message': 'foobar',

Sqlalchemy error, multiple foreign keys references to the same table and column

扶醉桌前 提交于 2021-02-17 06:44:05
问题 I already tried a solution from this question and this but failed (on of these solutions are present here), I don't know what to say additionally, logically both FK (sender and recipient) must be present in users, technically all looks are correct here class User(Base): __tablename__ = "users" # # # META # # # id = Column(Integer, primary_key=True, index=True) email = Column(String, unique=True, index=True, nullable=False) # # # RELATIONSHIPS # # # messages = relationship("Message", back

Sqlalchemy duplicated WHERE clause to FROM

本秂侑毒 提交于 2021-02-17 03:40:17
问题 I wrote raw query to psql and it's work fine but when i wrote this in sqlalchemy my WHERE clause duplicated to FROM clause. select id from T1 where arr && array(select l.id from T1 as l where l.box && box '((0,0),(50,50))'); In this query i fetch all id from T1 where array with ints intersects with results from subquery. class T1(): arr = Column(ARRAY(Integer)) ... class T2(): box = Column(Box) # my geometry type ... 1 verison: layers_q = select([T2.id]).where(T2.box.op('&&')(box)) # try find

How to use SQLAlchemy to create a full text search index on SQLite and query it?

我是研究僧i 提交于 2021-02-16 13:40:26
问题 I am create a simple app which can performance basic operations. SQLite is used as database. I want to perform wildcard search but I know that it has poor performance. I want to try out full text search but I cannot full a example on how to do it. I confirmed that SQLite has full text search support. Here is my sample code. from flask_sqlalchemy import SQLAlchemy db = SQLAlchemy() class Person(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.Text, unique=True,

How to use SQLAlchemy to create a full text search index on SQLite and query it?

被刻印的时光 ゝ 提交于 2021-02-16 13:40:09
问题 I am create a simple app which can performance basic operations. SQLite is used as database. I want to perform wildcard search but I know that it has poor performance. I want to try out full text search but I cannot full a example on how to do it. I confirmed that SQLite has full text search support. Here is my sample code. from flask_sqlalchemy import SQLAlchemy db = SQLAlchemy() class Person(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.Text, unique=True,

How do I return results from both tables in a SQLAlchemy JOIN?

旧巷老猫 提交于 2021-02-16 10:00:10
问题 I have two tables defined in my ORM as: Base = declarative_base() class GeneralLedger(Base): __tablename__ = 'generalledgers' id = Column(Integer, primary_key=True) invoiceId = Column(Integer) .. class ConsolidatedLedger(Base): __tablename__ = 'consolidatedledgers' id = Column(Integer, primary_key = True) invoiceId = Column(Integer) .. I don't have any relationship set between the two tables. I do a join as follows: records = DBSession.query(GeneralLedger).join(ConsolidatedLedger,

sqlalchemy raw sql query limit using connection.execute()

痞子三分冷 提交于 2021-02-16 06:28:51
问题 This python code should run statements on the database, but the sql statements are not executed: from sqlalchemy import * sql_file = open("test.sql","r") sql_query = sql_file.read() sql_file.close() engine = create_engine( 'postgresql+psycopg2://user:password@localhost/test', echo=False) conn = engine.connect() print sql_query result = conn.execute(sql_query) conn.close() The test.sql file contains SQL statements which create 89 tables. The tables are not created if I specify 89 tables, but

sqlalchemy raw sql query limit using connection.execute()

坚强是说给别人听的谎言 提交于 2021-02-16 06:25:49
问题 This python code should run statements on the database, but the sql statements are not executed: from sqlalchemy import * sql_file = open("test.sql","r") sql_query = sql_file.read() sql_file.close() engine = create_engine( 'postgresql+psycopg2://user:password@localhost/test', echo=False) conn = engine.connect() print sql_query result = conn.execute(sql_query) conn.close() The test.sql file contains SQL statements which create 89 tables. The tables are not created if I specify 89 tables, but

SQLAlchemy/MySQL Lost connection to MySQL server during query

老子叫甜甜 提交于 2021-02-16 05:08:35
问题 SQLAlchemy (0.9.8) and mysql-5.6.21-osx10.8-x86_64 and MAC OS X 10.3.3 (Yosemite) I keep getting intermittent: InterfaceError: (InterfaceError) 2013: Lost connection to MySQL server during query u'SELECT..... ' I have read up a few thread and most cases are resolved by adding this to my.cnf max_allowed_packet = 1024M which should be more than big enough for what I tried to do. After doing this, I step hit it intermittently. And putting this line in /etc/my.cnf: log-error = "/Users/<myname>

Flask SQLAlchemy Foreign Key Relationships

帅比萌擦擦* 提交于 2021-02-16 04:42:57
问题 I'm having a lot of trouble getting my head around foreign keys and relationships in SQLAlchemy. I have two tables in my database. The first one is Request and the second one is Agent . Each Request contains one Agent and each Agent has one Request . class Request(db.Model): __tablename__ = 'request' reference = db.Column(db.String(10), primary_key=True) applicationdate = db.Column(db.DateTime) agent = db.ForeignKey('request.agent'), class Agent(db.Model): __tablename__ = 'agent' id = db