Tagged Questions
0
votes
0answers
9 views
Self referential relationship is disappearing in flask-admin
Hope you can help me!
I have a relationship in sqlalchemy as follows:
class Location(db.Model, DateModified, Sluggable):
__tablename__ = 'location'
__sluggable__ = {
'populate_from': ...
0
votes
0answers
9 views
sqlalchemy schema: there is no unique constraint matching given keys for referenced table
I'm trying to create 2 tables using SQLAlchemy models that are identical in structure but distinct in purpose, the Whitelist and Blacklist which also reference a Magazine (not shown). They both fkey ...
1
vote
1answer
20 views
How do I express this query in SQL Alchemy
I am trying to query a table in an existing sqlite database. The data must first be subsetted as such, from a user input:
query(Data.num == input)
Then I want to find the max and min of another ...
1
vote
1answer
28 views
Flask sqlalchemy many-to-many insert data
Greetings,
I am trying to make a many to many relation here in Flask-SQLAlchemy, but it seems that I don't know how to fill the "many to many identifier database". Could you please help me ...
0
votes
1answer
22 views
How many Base or MetaData instances do you need in SQLAlchemy?
I'm currently reading the docs on SQLAlchemy for use in Flask and one thing that is very unclear to me is how many instances of certain SQLAlchemy objects (such as Base or MetaData) I need?
For ...
1
vote
0answers
15 views
Selecting columns from mulitple table join in SQLAlchemy Core
I am joining 3 table in SQLAlchemy Core and selecting all columns as follows:
rows = self.db.execute(self.execs.join(
self.orders.join(self.instruments)
...
0
votes
2answers
27 views
How can you map multiple tables to one model?
If I have two tables with same columns, ex. a table called Toyota and a table called Honda,
how can I map these two tables with one model (maybe called Car) in flask?
0
votes
1answer
14 views
Flask SQLAlchemy db.create_all() not creating database
I can't seem to figure out why my call to db.create_all() is not working.
I have an app package with following init:
from flask import Flask
from config import config
from flask.ext.sqlalchemy ...
0
votes
1answer
26 views
Flask SQLAlchemy relationship
I have a pretty simple model in Flask and SQLAlchemy, with companies playing matches. A match is defined by a host and a guest. I don't know how to bring the host and the guest companies to the ...
0
votes
1answer
7 views
SQLAlchemy ordered tree structure using association proxy object for positioning
I'm trying to create a simple tree structure of tasks. A Task can have a state (done:boolean) and a title (title:string) and any number of subtasks (tasks:Task[]). I've successfully managed to create ...
1
vote
2answers
42 views
Manually escape a string for raw SQL
I have a raw SQL statement to be executed using SqlAlchemy. The query contains this:
FROM unnest(array['sku1', 'sku2', 'sku3'])
Building the query manually, I could not find a way to escape each ...
0
votes
1answer
38 views
Converting SQLAlchemy ORM query results into JSON instead of creating ORM objects [duplicate]
I'm building a webapp for a small business, which is supposed to be some sort of mini ERP. The webapp is built with AngularJS, so I'm using the server side mostly to manage the database and provide a ...
0
votes
0answers
17 views
Generating JSON from SQLAlchemy [duplicate]
I have a JSON file I would like to generate from a database mapped using SQLAlchemy.
These are my classes :
class Node(Base):
__tablename__ = 'node'
id_node = Column(Integer, ...
1
vote
1answer
33 views
DateTime import using Pandas/SQLAlchemy
I'm having problems importing datetimes from a SQL Server database into Pandas.
I'm using the following code:
data = pd.read_sql('select top 10 timestamp from mytable',db)
'MyTable' contains a ...
0
votes
2answers
11 views
sqlalchemy many-to-many relationship, how to filter the collection
class Tag(Base):
__tablename__ = 'tags'
id = Column(Integer, primary_key=True, autoincrement=True)
slug = Column(String(50), unique=True, nullable=False)
class Post(Base):
...
0
votes
1answer
6 views
Wrong query result in sqlalchemy ZopeTransactionExtension
I have application on bottle.py. This application work with MySQL through sqlalchemy. Start version I am simple define session and do commit.
engine = create_engine(SQLALCHEMY_DATABASE_URI)
Session = ...
0
votes
1answer
16 views
SQLAlchemy Filter based on a function of an a field of a table
I am trying to filter a query based on a function of one of the properties of the table. For example assume, I have a table Days which has a property, day of the type DateTime. now I just want to ...
0
votes
1answer
13 views
How do I directly reference a table column in a database relationship?
Ok, my google-fu fails me. I want to have 2 relationships specified in a single table. Specifically, in the code below, I want to have the User.written field reference directly to the ...
0
votes
1answer
24 views
SQLAlchemy select with where constraint
I am trying to get a subset of a table from my database. The database is a MySql database.
Python code:
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, ...
0
votes
0answers
21 views
Is it possible to use HDF5 as backend for sqlalchemy or storm?
I have to deal with scientific data and HDF5 is my first choice. I try to keep my application logic separated from persistence code, therefore I am implementing some storage layer for storing and ...
0
votes
1answer
29 views
GroupBy and Sum in SQLAlchemy?
I am trying to group a few fields in a table, and then sum the groups, but they are getting double counted.
My models are as follows:
class CostCenter(db.Model):
__tablename__ = 'costcenter'
...
0
votes
1answer
30 views
Alembic migration issue with PostgreSQL schema and invalid one-to-many relationship
I've created a database and schema in Postgres. I have my models and when I run python manager.py db migrate which uses Flask-Migrate, I get the error below. However, the db init command works.
...
1
vote
1answer
36 views
How do I load only the specified columns and still get a model object? (without defer)
I want to:
Load only the fields I want, from multiple tables/models.
Get back "model objects", not the namedtuple-like objects I would from get passing the columns to session.query. This should span ...
0
votes
1answer
9 views
Python formatWarning and cross-package errors
Okay, I am confused. I am using two Python packages - PyPDF2 and SQLAlchemy. SQLAlchemy is raising a warning using python's warning.warn(), and somehow calling a formatWarning() function in PyPDF2, ...
0
votes
1answer
22 views
Creating Double precision columns using SqlAlchemy from Alembic
I need to use a DOUBLE column in my MYSQL db. I've read the docs, which suggest I use a Float with precision of 64. This, however, doesn't seem to be working. I end up with a regular float column, ...
0
votes
0answers
20 views
SqlAlchemy / Python Migrate drop_column if exists
I am having an issue with the following script from a openstack-keystone sql upgrade scripts
def upgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine
token = ...
0
votes
1answer
10 views
sqlalchemy treatment of attributes on read (staleness)
This might be a silly question, but I can't find the answer anywhere.
Let's say I pull some values:
widgets = session.query(Widget).all()
for widget in widgets:
# ... do lots of things here
...
0
votes
1answer
26 views
load a relationship in a to_json method
I have a fairly basic CRUDMixin
class CRUDMixin(object):
""" create, read, update and delete methods for SQLAlchemy """
id = db.Column(db.Integer, primary_key=True)
@property
def ...
0
votes
1answer
14 views
Close SQLAlchemy connection
I have the following function in python:
def add_odm_object(obj, table_name, primary_key, unique_column):
db = create_engine('mysql+pymysql://root:@127.0.0.1/mydb')
metadata = MetaData(db)
...
0
votes
0answers
4 views
Nested lists of relationships in SQLAlchemy
I'm trying to relate three models for my application: Bigram, Word, and Sentence.
A Bigram contains two Words (primary_word and secondary_word), but it also needs to record how often the ...
1
vote
1answer
44 views
Creating a query with few related tables in Pyramid with SQLAlchemy
I have defined few tables in Pyramid like this:
# coding: utf-8
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Integer, Float, DateTime, ForeignKey, ...
0
votes
0answers
6 views
OperationalError when Using sqlalchemy text [duplicate]
I'm trying to use sqlalchemy.sql.text to execute a query, as shown here but keep getting an OperationalError, no matter what I do. Here is some code which replicates my problem:
import sqlalchemy
...
0
votes
1answer
15 views
How to write a SQLAlchemy event listener for when a view within a specific Postgres schema is dropped?
In my app, whenever a view within a certain Postgres schema is dropped, I want to call a specific function. I am familiar with SQLAlchemy's event.listener functionality, but I have mainly seen it used ...
0
votes
1answer
28 views
how to call python script from javascript?
I have a backend python script where it retrieves the data from the sqlalchemy engine. And I would like to show the data in a search box where you can scroll down the list of data and select it. I ...
0
votes
1answer
7 views
Nested Joins in SQLAlchemy
How do I do nested joins in SQLAlchemy? The statement I'm trying to run is
SELECT a.col1, a.col2, c.col3
FROM a
LEFT OUTER JOIN (b INNER JOIN c ON c.col4 = b.col4) ON b.col5 = a.col5
I need to ...
0
votes
0answers
16 views
table valued function python
How to call table value function in python ?
Tried
In [73]: cur.callproc('fn_',('blah','12/31/2013','9/13/2014')) but doesn't work
Error:
MSSQLDatabaseException: (2809, "The request for ...
0
votes
2answers
21 views
Sqlalchemy - Foreign Value
I'm looking for a way to do the following.
class Foo(db.Model):
__tablename__ = 'foos_foo'
id = db.Column(db.Integer, primary_key=True)
author_id = db.Column(db.Integer, ...
0
votes
1answer
13 views
Counting relationships in SQLAlchemy
My SQLAlchemy structure looks like this
papers2authors_table = Table('papers2authors', Base.metadata,
Column('paper_id', Integer, ForeignKey('papers.id')),
Column('author_id', Integer, ...
0
votes
0answers
28 views
How to connect to a in-memory database in PyCharm?
When I connect to a jdbc:sqlite:///:memory: database (created by engine = create_engine("sqlite:///:memory:", ...)), PyCharm asks for a password, which is the same reaction as when PyCharm can't ...
0
votes
1answer
15 views
Storing to database in sqlalchemy with no values
I am trying an api in sql alchemy in which i am storing details of courses into database. The below code is the one i am used in which course name, start date, end date and hours per day are from the ...
1
vote
1answer
20 views
UNIQUE constraint failed in SQLAlchemy
I have two simple classes for SQLAlchemy:
papers2authors_table = Table('papers2authors', Base.metadata,
Column('paper_id', Integer, ForeignKey('papers.id')),
Column('author_id', Integer, ...
1
vote
1answer
34 views
SQLAlchemy, scoped_session - raw SQL INSERT doesn't write to DB
I have a Pyramid / SQLAlchemy, MySQL python app.
When I execute a raw SQL INSERT query, nothing gets written to the DB.
When using ORM, however, I can write to the DB. I read the docs, I read up ...
0
votes
2answers
25 views
Flask-SQLAlchemy many to many
Coming from Django, I am having a hard time figuring out just how the many to many relationship works.
The following models.py does not work, I get the error: InvalidRequestError: One or more mappers ...
0
votes
1answer
13 views
SQLAlchemy One-To-One and One-To-Many at the same time (AmbiguousForeignKeysError)
I'm working with SQLAlchemy and I try to achieve one-to-one and one-to-many relationships on the same parent class.
This is for the simplicity of keeping track of the main child entity.
Unfortunately ...
0
votes
0answers
32 views
if I don't use foreignkey, How could I connect relation
class PubSquare(db.Model):
id = db.Column(db.Integer, primary_key=True)
author_id = db.Column(db.Integer)
subject = db.Column(db.String(60))
timestamp = db.Column(db.DateTime, ...
1
vote
0answers
38 views
What is causing this CircularDependencyError and how is it fixed?
When I try to migrate my database I get a CircularDependencyError. I found some information about this in the Core Exceptions docs and tried to add post_update=True, but it didn't solve the issue. I ...
0
votes
0answers
15 views
sqlalchemy: persist a selected instance from the session
I am trying to implement the repository pattern using the sql.Session from sqlalchemy orm, my problem is that I cannot find a way to commit the changes from an instance without commit the other dirty ...
0
votes
1answer
16 views
Python ,SQLAlchemy, get id from database
I want to make a Python (SQLAlchemy) program that takes the ID from a table according to a value.
For example, I have a table like this :
-------------------------------
| ID | Name ...
2
votes
1answer
1k views
SQLAlchemy create_all() does not create tables
I'm trying to integrate PostgreSQL and SQLAlchemy but SQLAlchemy.create_all() is not creating any tables from my models.
My code:
from flask import Flask
from flask.ext.sqlalchemy import ...
1
vote
1answer
1k views
How can I search the table of a Flask SQLAlchemy many to many relationship?
I have the following models and table:
chat_members = db.Table('chat_members',
db.Column('user_id', db.Integer, db.ForeignKey('user.id')),
db.Column('chat_id', db.Integer, ...