sqlalchemy

Column does not exist error on CreateTable

久未见 提交于 2021-02-11 15:08:39
问题 I'm trying to print out DDLs for all the tables in Redshift database. My code look something like this: cnxn = engine.connect() metadata = MetaData(bind=engine, schema=SCHEMA) metadata.reflect(bind=engine) for table in metadata.sorted_tables: try: res = CreateTable(table).compile(engine) print(res) except ProgrammingError as e: print(f"Failed to compile DDL for {table}: {e}") continue I've tested this code on other redshift databases and it seems to work fine. But in this database it fails

How to fetch rows with max update datetime using GROUP BY and HAVING with SQLAlchemy and Postgresql

杀马特。学长 韩版系。学妹 提交于 2021-02-11 14:52:04
问题 I'm going from SQLite to Postgresql. This has made one of my queries not work. It's not clear to me why this query is allowed in SQLite, but not in Postgresql. The query in question is below in the find_recent_by_section_id_list() function. I've tried rewriting the query in multiple ways, but what is confusing me is that this query worked when I was working with SQLite. The setup is Flask, SQLAlchemy, Flask-SQLAlchemy and Postgresql. class SectionStatusModel(db.Model): __tablename__ =

Creating a View while joining two tables in Alchemy

不打扰是莪最后的温柔 提交于 2021-02-11 14:46:30
问题 I m trying to join two tables and inserting the data in a view in PostgreSQL. While i debug I can see my data but when i check my DB there is no creating of a view. ALso the is nothing as error and i cannot find what's missing. engine = create_engine(DATABASE_URI) view = Table('testing', MetaData()) session = get_db_session() result=session.query(Policy_table,Join_table).filter(Policy_table.name==Join_table.policy_name).all() session.commit() create_view = CreateView(view ,result) engine

How to set DATABASE_URL environment variable for Postgres Mac terminal?

旧时模样 提交于 2021-02-11 14:45:19
问题 I am using postgres on Mac. I have a database up and running. I want to use it with Flask (SQL Alchemy) but the DATABASE_URL environment variable didn't create itself (I think it's supposed to do that). Here is the code I tried running: import os print(os.getenv("DATABASE_URL")) And there's no output. How can I set the variable (if I need to set it up manually). 回答1: Yes, you have to do that manually. So, within your terminal do this: % cd % nano .bash_profile It will open a file 'bash

AttributeError: 'tuple' object has no attribute 'keys'

狂风中的少年 提交于 2021-02-11 13:40:59
问题 I'm trying to insert some data to my table in MSSQL using flask+sqlalchemy. I'm using Python 3.4. My code: @main.route('/create-user', methods=['GET', 'POST']) def create_user(): form = NewUser() if form.validate_on_submit(): login = form.name.data passwrd = form.password.data print (login) #getting login is ok print (passwrd) #same engine.execute( text("INSERT INTO my_table VALUES ((CONVERT(binary, :login)), (CONVERT(binary, :passwrd)))"), login, passwrd) session.commit() flash('Succesfull')

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

pymysql.err.OperationalError - Lost connection to MySQL server during query

让人想犯罪 __ 提交于 2021-02-11 12:07:43
问题 I am using Python script to insert records into MySQL database table. The script fails with the following error message. MySQL version is 8.0.17 , Python version 3.6.5 (pymysql.err.OperationalError) (2013, 'Lost connection to MySQL server during query ([WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond)') (Background on this error at: http:/

pymysql.err.OperationalError - Lost connection to MySQL server during query

筅森魡賤 提交于 2021-02-11 12:04:45
问题 I am using Python script to insert records into MySQL database table. The script fails with the following error message. MySQL version is 8.0.17 , Python version 3.6.5 (pymysql.err.OperationalError) (2013, 'Lost connection to MySQL server during query ([WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond)') (Background on this error at: http:/

SQLAlchemy get position when ordered by value?

情到浓时终转凉″ 提交于 2021-02-11 04:41:47
问题 I have a table which stores some movie info and a score. I want to be able to know what position a movie has after being ordered by that score (ie 'The Shining' has the 10th highest score) but it would obvisouly not necessarily be in the tenth place of the database or have the id 10. Would it be possible to get something like this, either through a query or somehow keeping it as a value in the table? Thank you! The table looks like this: class MoviePersonScores(db.Model): movie_id = db.Column

SQLAlchemy get position when ordered by value?

天大地大妈咪最大 提交于 2021-02-11 04:31:56
问题 I have a table which stores some movie info and a score. I want to be able to know what position a movie has after being ordered by that score (ie 'The Shining' has the 10th highest score) but it would obvisouly not necessarily be in the tenth place of the database or have the id 10. Would it be possible to get something like this, either through a query or somehow keeping it as a value in the table? Thank you! The table looks like this: class MoviePersonScores(db.Model): movie_id = db.Column