alembic

Creating seed data in a flask-migrate or alembic migration

我的未来我决定 提交于 2019-11-28 15:49:24
问题 How can I insert some seed data in my first migration? If the migration is not the best place for this, then what is the best practice? """empty message Revision ID: 384cfaaaa0be Revises: None Create Date: 2013-10-11 16:36:34.696069 """ # revision identifiers, used by Alembic. revision = '384cfaaaa0be' down_revision = None from alembic import op import sqlalchemy as sa def upgrade(): ### commands auto generated by Alembic - please adjust! ### op.create_table('list_type', sa.Column('id', sa

Using Alembic API from inside application code

半城伤御伤魂 提交于 2019-11-28 05:46:07
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 to the newest format. Also, I create temporary databases a lot to save subsets of the data for use

Alembic - sqlalchemy initial migration

ぐ巨炮叔叔 提交于 2019-11-28 03:59:29
问题 I am having a problem creating an initial migration which would automatically have tables that I've defined in my models.py by using shared Base (declarative_base). When I enter a command: alembic revision --autogenerate alembic creates an empty file. What's wrong in my configs or my approach? project.base.py: from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() env.py: import sys import os sys.path.append(os.path.abspath(os.getcwd())) from alembic import context

Alembic --autogenerate producing empty migration

落爺英雄遲暮 提交于 2019-11-27 15:47:30
问题 I am trying to use Alembic for the first time and want to use --autogenerate feature described here My project structure looks like project/ configuration/ __init__.py dev.py test.py core/ app/ models/ __init__.py user.py db/ alembic/ versions/ env.py alembic.ini I am using Flask and SQLAlchemy and their Flask-SQLAlchemy extension. my model User looks like class User(UserMixin, db.Model): __tablename__ = 'users' # noinspection PyShadowingBuiltins uuid = Column('uuid', GUID(), default=uuid

How to handle python packages with conflicting names?

拜拜、爱过 提交于 2019-11-27 13:59:18
问题 I'm using two python packages that have the same name. http://www.alembic.io/updates.html https://pypi.python.org/pypi/alembic Is there a canonical or pythonic way to handle installing two packages with conflicting names? So far, I've only occasionally needed one of the packages during development/building, so I've been using a separate virtualenv to deal with the conflict, but it makes the build step more complex and I wonder if there isn't a better way to handle it. 回答1: You could use the -

Modify data as part of an alembic upgrade

∥☆過路亽.° 提交于 2019-11-27 13:39:27
问题 I would like to modify some database data as part of an alembic upgrade. I thought I could just add any code in the upgrade of my migration, but the following fails: def upgrade(): ### commands auto generated by Alembic - please adjust! ### op.add_column('smsdelivery', sa.Column('sms_message_part_id', sa.Integer(), sa.ForeignKey('smsmessagepart.id'), nullable=True)) ### end Alembic commands ### from volunteer.models import DBSession, SmsDelivery, SmsMessagePart for sms_delivery in DBSession

Target database is not up to date

送分小仙女□ 提交于 2019-11-27 11:25:05
问题 I'd like to make a migration for a Flask app. I am using Alembic. However, I receive the following error. Target database is not up to date. Online, I read that it has something to do with this. http://alembic.zzzcomputing.com/en/latest/cookbook.html#building-an-up-to-date-database-from-scratch Unfortunately, I don't quite understand how to get the database up to date and where/how I should write the code given in the link. If you have experience with migrations, can you please explain this

How do I execute inserts and updates in an Alembic upgrade script?

给你一囗甜甜゛ 提交于 2019-11-27 02:57:32
I need to alter data during an Alembic upgrade. I currently have a 'players' table in a first revision: def upgrade(): op.create_table('player', sa.Column('id', sa.Integer(), nullable=False), sa.Column('name', sa.Unicode(length=200), nullable=False), sa.Column('position', sa.Unicode(length=200), nullable=True), sa.Column('team', sa.Unicode(length=100), nullable=True) sa.PrimaryKeyConstraint('id') ) I want to introduce a 'teams' table. I've created a second revision: def upgrade(): op.create_table('teams', sa.Column('id', sa.Integer(), nullable=False), sa.Column('name', sa.String(length=80),

How do I execute inserts and updates in an Alembic upgrade script?

倖福魔咒の 提交于 2019-11-26 10:15:32
问题 I need to alter data during an Alembic upgrade. I currently have a \'players\' table in a first revision: def upgrade(): op.create_table(\'player\', sa.Column(\'id\', sa.Integer(), nullable=False), sa.Column(\'name\', sa.Unicode(length=200), nullable=False), sa.Column(\'position\', sa.Unicode(length=200), nullable=True), sa.Column(\'team\', sa.Unicode(length=100), nullable=True) sa.PrimaryKeyConstraint(\'id\') ) I want to introduce a \'teams\' table. I\'ve created a second revision: def