sqlalchemy

flask sqlalchemy many to many relationship with extra field

天大地大妈咪最大 提交于 2020-12-29 09:06:20
问题 I have 2 tables: restaurants and foods, and a 3rd table restaurants_foods which stores the many to many relationship between the 2 tables restaurants_foods = db.Table('restaurants_foods', db.Column('restaurant_id', db.Integer, db.ForeignKey('restaurants.id'), primary_key=True), db.Column('food_id', db.Integer, db.ForeignKey('foods.id'), primary_key=True), db.Column('food_price', db.Float) ) class Food(Model): __tablename__ = "foods" id = db.Column(db.Integer, primary_key=True, autoincrement

Using Dask's NEW to_sql for improved efficiency (memory/speed) or alternative to get data from dask dataframe into SQL Server Table

喜夏-厌秋 提交于 2020-12-29 06:52:31
问题 My ultimate goal is to use SQL/Python together for a project with too much data for pandas to handle (at least on my machine). So, I have gone with dask to: read in data from multiple sources (mostly SQL Server Tables/Views) manipulate/merge the data into one large dask dataframe table of ~10 million+ rows and 52 columns, some of which have some long unique strings write it back to SQL Server on a daily basis, so that my PowerBI report can automatically refresh the data. For #1 and #2, they

Undo last Alembic migration

和自甴很熟 提交于 2020-12-29 05:01:38
问题 I created a migration with alembic revision --autogenerate , applied it to my development database with alembic upgrade head , and then realised it wasn't quite what I wanted. How can I revert the migration so that I can tweak it and try again? 回答1: Assuming that you only want to go back one revision, use alembic downgrade with a relative migration identifier of -1: alembic downgrade -1 This will run the downgrade() method of your latest revision and update the revision table to indicate the

Undo last Alembic migration

こ雲淡風輕ζ 提交于 2020-12-29 04:58:17
问题 I created a migration with alembic revision --autogenerate , applied it to my development database with alembic upgrade head , and then realised it wasn't quite what I wanted. How can I revert the migration so that I can tweak it and try again? 回答1: Assuming that you only want to go back one revision, use alembic downgrade with a relative migration identifier of -1: alembic downgrade -1 This will run the downgrade() method of your latest revision and update the revision table to indicate the

SQLAlchemy - what is declarative_base

女生的网名这么多〃 提交于 2020-12-28 05:45:38
问题 I am learning sqlalchemy . Here is my initial code : user.py from sqlalchemy import Column, Integer, Sequence, String from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() class User(Base): __tablename__ = 'users' id = Column(Integer,Sequence('user_seq'), primary_key=True) username = Column(String(50), unique=True) fullname = Column(String(150)) password = Column(String(50)) def __init__(self, name, fullname, password): self.name = name self.fullname = fullname

SQLAlchemy - what is declarative_base

杀马特。学长 韩版系。学妹 提交于 2020-12-28 05:45:03
问题 I am learning sqlalchemy . Here is my initial code : user.py from sqlalchemy import Column, Integer, Sequence, String from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() class User(Base): __tablename__ = 'users' id = Column(Integer,Sequence('user_seq'), primary_key=True) username = Column(String(50), unique=True) fullname = Column(String(150)) password = Column(String(50)) def __init__(self, name, fullname, password): self.name = name self.fullname = fullname

SQLAlchemy - what is declarative_base

你。 提交于 2020-12-28 05:44:23
问题 I am learning sqlalchemy . Here is my initial code : user.py from sqlalchemy import Column, Integer, Sequence, String from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() class User(Base): __tablename__ = 'users' id = Column(Integer,Sequence('user_seq'), primary_key=True) username = Column(String(50), unique=True) fullname = Column(String(150)) password = Column(String(50)) def __init__(self, name, fullname, password): self.name = name self.fullname = fullname

SQLAlchemy - 'Table' object has no attribute '_query_cls' when querying a table obtained with reflect

微笑、不失礼 提交于 2020-12-26 08:42:42
问题 I am trying to query a table with SQL Alchemy ORM that I connected to using reflect (it is an existing database). I tried to use the method described here: How to query a table, in sqlalchemy to query the data but I got an error. from sqlalchemy import create_engine, MetaData from sqlalchemy.orm import Session engine = create_engine(db_uri) metadata = MetaData(engine) metadata.reflect() table = metadata.tables["events"] Session.query(table).all() I get the following error: Traceback (most

Pandas read_sql_query returning None for all values in some columns

岁酱吖の 提交于 2020-12-26 08:11:18
问题 I am using pandas read_sql_query to read data from a MySQL database table into a pandas dataframe. Some columns in this table have all NULL values. For those columns the pandas dataframe contains None in every row. For all other columns the dataframe contains NaN where there was a NULL value. Can anyone explain why None is returned for the all NULL columns? And how do I make sure I have all NaNs, hopefully without doing manual conversions? I should add that two of the columns causing this

Snowflake pandas pd_writer writes out tables with NULLs

久未见 提交于 2020-12-26 06:45:42
问题 I have a Pandas dataframe that I'm writing out to Snowflake using SQLAlchemy engine and the to_sql function. It works fine, but I have to use the chunksize option because of some Snowflake limit. This is also fine for smaller dataframes. However, some dataframes are 500k+ rows, and at a 15k records per chunk, it takes forever to complete writing to Snowflake. I did some research and came across the pd_writer method provided by Snowflake, which apparently loads the dataframe much faster. My