alembic

Sqlite lack of ALTER support, Alembic migration failing because of this. Solutions?

时光怂恿深爱的人放手 提交于 2021-01-20 17:46:46
问题 I am developing a small registration application for a friend zumba class, using Flask, SQLAlchemy and Flask-migrate(alembic) to deal with db update. I settled on SQlite because the application has to be self contained and runs locally on a laptop without internet access and SQLite requires no installation of a service or other, which is a must too. Dealing with SQLite lack of support of ALTER table wasn't a problem during the initial development as I simply destroyed, recreated the DB when

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 + alembic: create schema migration

喜欢而已 提交于 2020-08-24 06:04:50
问题 I'm not sure how to define a create schema foo migration? My Model looks like this (I'm using Flask-Migrate): class MyTable(db.Model): __tablename__ = "my_table" __table_args__ = {"schema": "foo"} id = ColumnPrimKey() name = Column(Text, unique=True, nullable=False) When I execute mange db upgrade I get a failure because the schema "foo" does not exist. How can I add a migration for the schema with SQLAlchemy and Alembic? 回答1: I accomplished this by modifying the migration upgrade command to

SQLAlchemy + alembic: create schema migration

江枫思渺然 提交于 2020-08-24 06:04:48
问题 I'm not sure how to define a create schema foo migration? My Model looks like this (I'm using Flask-Migrate): class MyTable(db.Model): __tablename__ = "my_table" __table_args__ = {"schema": "foo"} id = ColumnPrimKey() name = Column(Text, unique=True, nullable=False) When I execute mange db upgrade I get a failure because the schema "foo" does not exist. How can I add a migration for the schema with SQLAlchemy and Alembic? 回答1: I accomplished this by modifying the migration upgrade command to

How to sync db with Flask-Migrate in a fresh application deployment?

佐手、 提交于 2020-05-15 07:45:36
问题 When deploying an application to a fresh server (i.e. the database is empty) how do I sync the database properly with Flask-Migrate? I've added Flask-Migrate to the project when I already had some schema in place so I don't have "initial" migrations with all create_table() . Now when I do manage.py db upgrade in my deployment script I get relation "..." does not exist . Is there any built-in way to detect empty database and run 'create_all()' instead of migrations? This is what the Alembic's

MySQL DB migration: change of string length

点点圈 提交于 2020-04-07 05:08:34
问题 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