flask-migrate

flask-migrate doesn't work When I add models with ForeignKey

橙三吉。 提交于 2019-12-04 22:00:15
class User(db.Model): __tablename__ = 'user' id = db.Column(db.Integer, primary_key=True) email = db.Column(db.String(64), unique=True) # 是不是应该加密下,不能明文存储?应该设置多长的空间? 14.7.18 4:22 by lee password = db.Column(db.String(100)) nickname = db.Column(db.String(64)) school = db.Column(db.String(20)) sex = db.Column(db.String(5)) status = db.Column(db.String(10)) grade = db.Column(db.String(18)) I have a database remains. Then I add model to models.py: class PubSquare(db.Model): id = db.Column(db.Integer, primary_key=True) author_id = db.Column(db.Integer, db.ForeignKey('user.id')) author = db

sqlalchemy postgresql enum does not create type on db migrate

雨燕双飞 提交于 2019-12-03 10:46:07
问题 I develop a web-app using Flask under Python3. I have a problem with postgresql enum type on db migrate/upgrade. I added a column "status" to model: class Banner(db.Model): ... status = db.Column(db.Enum('active', 'inactive', 'archive', name='banner_status')) ... Generated migration by python manage.py db migrate is: from alembic import op import sqlalchemy as sa def upgrade(): op.add_column('banner', sa.Column('status', sa.Enum('active', 'inactive', 'archive', name='banner_status'), nullable

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

て烟熏妆下的殇ゞ 提交于 2019-12-03 07:42:33
问题 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

Cannot complete Flask-Migration

扶醉桌前 提交于 2019-12-03 07:11:56
问题 I've setup a local Postgres DB with SQLAlchemy and cannot commit my first entry. I keep on getting this error... ProgrammingError: (ProgrammingError) relation "user" does not exist LINE 1: INSERT INTO "user" (name, email, facebook_id, facebook_token... It seems like the fields aren't matching to those in the database. I'm trying to migrate using flask-migrate but, when I run $ python app.py db migrate I get this error... raise util.CommandError("No such revision '%s'" % id_) alembic.util

Why Flask-migrate cannot upgrade when drop column

我只是一个虾纸丫 提交于 2019-12-03 02:20:41
问题 I am using SqlAlchemy and Flask-migrate for DB migration. I have successfully init the DB and upgrade once, but when I deleted one of my table column, I managed to migrate however upgrade gave me the following error: sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) near "DROP": syntax error [SQL: u'ALTER TABLE posts DROP COLUMN tags'] There is part of my models.py class Post(db.Model): __tabelname__ = 'posts' id = db.Column(db.Integer, primary_key=True) body = db.Column(db

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

Cannot complete Flask-Migration

依然范特西╮ 提交于 2019-12-02 20:49:09
I've setup a local Postgres DB with SQLAlchemy and cannot commit my first entry. I keep on getting this error... ProgrammingError: (ProgrammingError) relation "user" does not exist LINE 1: INSERT INTO "user" (name, email, facebook_id, facebook_token... It seems like the fields aren't matching to those in the database. I'm trying to migrate using flask-migrate but, when I run $ python app.py db migrate I get this error... raise util.CommandError("No such revision '%s'" % id_) alembic.util.CommandError: No such revision '39408d6b248d' It may be best to delete everything and start from scratch as

Why Flask-migrate cannot upgrade when drop column

痞子三分冷 提交于 2019-12-02 15:51:50
I am using SqlAlchemy and Flask-migrate for DB migration. I have successfully init the DB and upgrade once, but when I deleted one of my table column, I managed to migrate however upgrade gave me the following error: sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) near "DROP": syntax error [SQL: u'ALTER TABLE posts DROP COLUMN tags'] There is part of my models.py class Post(db.Model): __tabelname__ = 'posts' id = db.Column(db.Integer, primary_key=True) body = db.Column(db.UnicodeText) # tags = db.Column(db.Unicode(32)) # I deleted this field, upgrade give me error .... And I run

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)