alembic

MySQL DB migration: change of string length

早过忘川 提交于 2020-04-07 05:07:36
问题 I'm using SQLAlchemy + alembic to manage my database. I had a string field which was 10 characters long and later on found out that it has to be 20. So I updated the model definition. class Foo(db.Model): __tablename__ = 'foos' id = db.Column(db.Integer, primary_key=True) foo_id = db.Column(db.Integer, db.ForeignKey('users.id')) name = db.Column(db.String(80)) When I run alembic revision --autogenerate , this was not detected. Now I did read the documentation and suspected that this might not

Python - Packaging Alembic Migrations with Setuptools

夙愿已清 提交于 2020-02-23 08:50:11
问题 What is the right way to package Alembic migration files in a Setuptools setup.py file? Everything is in my repo root as alembic/ . This is a Python application, not a library. My desired installation flow is that someone can pip install the wheel that is my application. They would then be able to initialize the application database by running something like <app> alembic upgrade --sqlalchemy.url=<db_url> . Upgrades would then require a pip install -U , after which they can run the Alembic

Specify join condition in SQLalchemy ORM without foreign key

允我心安 提交于 2020-01-23 20:31:33
问题 I have two models in SQLAlchemy that I had automatically joining on a foreign key, like so: class Parent(Base): __tablename__ = 'parents' id = Column(Integer, primary_key=True) name = Column(String(300), nullable=False) metadata_id = Column(Integer, nullable=True, index=True) class Child(Base): __tablename__ = 'children' id = Column(Integer, primary_key=True) name = Column(String(300), nullable=False) parent_metadata_id = \ Column(ForeignKey('parents.metadata_id'), nullable=True, primary_key

Alembic bulk_insert to table with schema

余生颓废 提交于 2020-01-04 17:30:33
问题 I'm looking at the example at bulk_insert. # Create an ad-hoc table to use for the insert statement. accounts_table = table('account', column('id', Integer), column('name', String), column('create_date', Date) ) I would like to bulk insert to a specific schema called kpi but I can't figure out how to do it. Can someone help me out? 回答1: The answer I've found so far is to use the sqlalchemy function instead like below: accounts_table = sa.Table('accounts_table', sa.MetaData(), sa.Column('id',

Alembic: alter column type with USING

旧巷老猫 提交于 2020-01-01 01:11:08
问题 I'm attempting to use alembic to convert a SQLAlchemy PostgreSQL ARRAY(Text) field to a BIT(varying=True) field for one of my table columns. The column is currently defined as: cols = Column(ARRAY(TEXT), nullable=False, index=True) I want to change it to: cols = Column(BIT(varying=True), nullable=False, index=True) Changing column types doesn't seem to be supported by default, so I'm editing the alembic script by hand. This is what I have currently: def upgrade(): op.alter_column( table_name=

No changes detected in Alembic autogeneration of migrations with Flask-SQLAlchemy

跟風遠走 提交于 2019-12-29 20:17:12
问题 I'm having trouble getting Alembic to autogenerate candidate migrations from changes to classes using db.Model (Flask-SQLAlchemy) instead of Base . I've modified env.py to create my Flask app, import all relevant models, initialize the database, and then run migrations: ... uri = 'mysql://user:password@host/dbname?charset=utf8' app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = uri app.config['SQLALCHEMY_ECHO'] = True db.init_app(app) with app.test_request_context(): target

Using Alembic API from inside application code

杀马特。学长 韩版系。学妹 提交于 2019-12-28 11:46:04
问题 I am using SQLite as an application file format (see here for why you would want to do this) for my PySide-based desktop application. That is, when a user uses my app, their data is saved in a single database file on their machine. I am using the SQLAlchemy ORM to communicate with the databases. As I release new versions of the application, I may modify the database schema. I don't want users to have to throw away their data every time I change the schema, so I need to migrate their databases

Using Alembic API from inside application code

只愿长相守 提交于 2019-12-28 11:45:09
问题 I am using SQLite as an application file format (see here for why you would want to do this) for my PySide-based desktop application. That is, when a user uses my app, their data is saved in a single database file on their machine. I am using the SQLAlchemy ORM to communicate with the databases. As I release new versions of the application, I may modify the database schema. I don't want users to have to throw away their data every time I change the schema, so I need to migrate their databases

Using Alembic API from inside application code

点点圈 提交于 2019-12-28 11:45:02
问题 I am using SQLite as an application file format (see here for why you would want to do this) for my PySide-based desktop application. That is, when a user uses my app, their data is saved in a single database file on their machine. I am using the SQLAlchemy ORM to communicate with the databases. As I release new versions of the application, I may modify the database schema. I don't want users to have to throw away their data every time I change the schema, so I need to migrate their databases

Alembic SqlAlchemy Postgres “NameError: name 'String' is not defined” trying to add Array(String) fields

烂漫一生 提交于 2019-12-25 06:59:56
问题 The Model is below plus error message below that. I am trying to create some array columns using Alembic but getting NameError: name 'String' is not defined. Any help valued. thanks! from sqlalchemy import Column, String, Integer, DateTime from serve_spec.db_global import db import datetime from time import time from sqlalchemy.dialects.postgresql import JSON from sqlalchemy.dialects.postgresql import ARRAY class Issues(db.Base): __tablename__ = 'issues' id = Column(String, primary_key=True)