alembic

Alembic: alter column type with USING

∥☆過路亽.° 提交于 2019-12-03 04:22:00
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='views', column_name='cols', nullable=False, type_=postgresql.BIT(varying=True) ) def downgrade(): op

alembic util command error can't find identifier

[亡魂溺海] 提交于 2019-12-03 02:39:00
问题 I'm trying to use alembic to handle local migrations on my project. It worked the first time, but then I needed to delete the folder and restart.(don't ask why, I just had to) I'm following this tutorial and I run the command python manage.py db init And it was ok. But when I try to run python manage.py db migrate I'm getting this error: alembic.util.CommandError: Can't locate revision identified by '31b8ab83c7d' Now, it seems that alembic is looking for a revision that doesn't exists anymore

How do you add migrate an existing database with alembic/flask-migrate if you did not start off with it?

房东的猫 提交于 2019-12-02 21:18:22
This is the chain of events that has and is happening Day 0: I developed and deployed my app Day 1: I create the new database Day 3: I realized I wanted to add a new row to my existing table. I found flask-migrate and I want to use it to migrate my database. Currently I am at Day 3 There are plenty of documentations on how to get Flask-migrate running if you start from Day 0. You just call flask db init , flask db migrate and flask db upgrade . However, for my case, it's a bit different. I ran the commands, and my first version of migration is empty . Then I modified my database schema and

Alembic: IntegrityError: “column contains null values” when adding non-nullable column

▼魔方 西西 提交于 2019-12-02 19:01:42
I'm adding a column to an existing table. This new column is nullable=False . op.add_column('mytable', sa.Column('mycolumn', sa.String(), nullable=False)) When I run the migration, it complains: sqlalchemy.exc.IntegrityError: column "mycolumn" contains null values Ron It is because your existing data have no value on that new column, i.e. null . Thus causing said error. When adding a non-nullable column, you must decide what value to give to already-existing data Alright, existing data should just have "lorem ipsum" for this new column then. But how do I do it? I can't UPDATE because the

alembic util command error can't find identifier

谁都会走 提交于 2019-12-02 16:13:53
I'm trying to use alembic to handle local migrations on my project. It worked the first time, but then I needed to delete the folder and restart.(don't ask why, I just had to) I'm following this tutorial and I run the command python manage.py db init And it was ok. But when I try to run python manage.py db migrate I'm getting this error: alembic.util.CommandError: Can't locate revision identified by '31b8ab83c7d' Now, it seems that alembic is looking for a revision that doesn't exists anymore. There is anyway to make alembic forget that file? Or like restart the comparison from None to -> auto

Getting Flask-Migrate to Ignore SQL Views that are mapped as Flask-SQLAlchemy Models

谁说我不能喝 提交于 2019-12-01 21:46:46
问题 I am using Flask-SQLAlchemy to define my models, and then using Flask-Migrate to auto-generate migration scripts for deployment onto a PostgreSQL database. I have defined a number of SQL Views on the database that I use in my application like below. However, Flask-Migrate now generates a migration file for the view as it thinks it's a table. How do I correctly get Flask-Migrate / Alembic to ignore the view during autogenerate? SQL View name: vw_SampleView with two columns: id and rowcount .

Getting Flask-Migrate to Ignore SQL Views that are mapped as Flask-SQLAlchemy Models

荒凉一梦 提交于 2019-12-01 19:17:59
I am using Flask-SQLAlchemy to define my models, and then using Flask-Migrate to auto-generate migration scripts for deployment onto a PostgreSQL database. I have defined a number of SQL Views on the database that I use in my application like below. However, Flask-Migrate now generates a migration file for the view as it thinks it's a table. How do I correctly get Flask-Migrate / Alembic to ignore the view during autogenerate? SQL View name: vw_SampleView with two columns: id and rowcount . class ViewSampleView(db.Model): __tablename__ = 'vw_report_high_level_count' info = dict(is_view=True)

How to turn on 'PRAGMA foreign_keys = ON' in sqlalchemy migration script or configuration file for sqlite?

女生的网名这么多〃 提交于 2019-12-01 08:37:21
问题 In a suitable sqlite version, we can enforce foreign key constraint by 'PRAGMA foreign_keys = ON'. However user can not log in a database every time when making a connection. So I wonder how can we make it working in a migration script in sqlalchemy/alembic? Thanks very much! 回答1: See Foreign Key Support from SA SQLite documentation: import sqlite3 from sqlalchemy.engine import Engine from sqlalchemy import event @event.listens_for(Engine, "connect") def set_sqlite_pragma(dbapi_connection,

Adding primary key to existing MySQL table in alembic

限于喜欢 提交于 2019-12-01 04:09:16
I am trying to add an 'id' primary key column to an already existing MySQL table using alembic. I tried the following... op.add_column('mytable', sa.Column('id', sa.Integer(), nullable=False)) op.alter_column('mytable', 'id', autoincrement=True, existing_type=sa.Integer(), existing_server_default=False, existing_nullable=False) but got the following error sqlalchemy.exc.OperationalError: (OperationalError) (1075, 'Incorrect table definition; there can be only one auto column and it must be defined as a key') 'ALTER TABLE mytable CHANGE id id INTEGER NOT NULL AUTO_INCREMENT' () looks like the

Flask-migrate and changing column type

谁说胖子不能爱 提交于 2019-11-30 15:07:55
问题 I am trying to learn some Flask and I am using Flask-Migrate 1.6.0 So I made a model which looks like this class Download(db.Model): __tablename__ = "downloads" id = db.Column(db.Integer, autoincrement=True, primary_key=True) filename = db.Column(db.String, nullable=False) size = db.Column(db.Integer, nullable=False) location = db.Column(db.String, nullable=False) season = db.Column(db.Integer, nullable=False) download_timestamp = db.Column(db.DateTime, nullable=False) show_id = db.Column(db