flask-migrate

How to use Flask-Migrate to do database migration?

倖福魔咒の 提交于 2020-01-30 11:42:10
问题 I come across a problem when playing with Flask-Migrate to upgrade/downgrade the database. There were two tables, User and Post , defined by the following classes: class User(db.Model): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(64), index=True, unique=True) email = db.Column(db.String(120), index=True, unique=True) password_hash = db.Column(db.String(128)) posts = db.relationship('Post', backref='author', lazy='dynamic') def __repr__(self): return '<User {}>'

Flask-migrate multiple models.py

人盡茶涼 提交于 2019-12-25 02:47:14
问题 I've a question related to Flask-migrate. I'm creating a set of web services with Flask. I've split each web service in his own package in a python application. The application structure look like this: MyApp WS1 models.py WS2 models.py CommonPackage models.py How can I import all the modules and init the db? I've tried to import them all manually but is not working. I know that it works if I import the "app" from WS1 or Ws2 separately, but I would like to do this in a single operation, is

How can I migrate a table with data in a table which got a new datetime column which is non-nullable?

邮差的信 提交于 2019-12-24 19:25:15
问题 I've added a column registered_on = db.Column(db.DateTime, nullable=False) to my users table. The migration which was automatically created is def upgrade(): # ### commands auto generated by Alembic - please adjust! ### ... op.add_column('users', sa.Column('registered_on', sa.DateTime(), nullable=False)) ... When I execute it, I got an exception about an invalid value 0000-00-00 00:00:00 (or so). How should I adjust the migration script to not have this problem? (In this situation, filling in

Flask Migrate using different postgres schemas ( __table_args__ = {'schema': 'test_schema']})

一个人想着一个人 提交于 2019-12-24 02:04:47
问题 I'm trying to use flask, sqlalchemy, and flask_migrate... But every time run manage.py migrate, alembic always detect my model as a new table. I think that i put table_args in my model to store table in a different postgres schema: class Entry(db.Model): __table_args__ = {'schema': app.config['BASE_SCH']} id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(100)) slug = db.Column(db.String(100), unique=True) body = db.Column(db.Text) status = db.Column(db.SmallInteger,

In Flask-migrate ValueError: invalid interpolation syntax in connection string at position 15

荒凉一梦 提交于 2019-12-19 05:48:32
问题 I am using flask migrate to for database creation & migration in flask with flask-sqlalchemy. Everything was working fine until I changed my database user password contains '@' then it stopped working so, I updated my code based on Writing a connection string when password contains special characters It working for application but not for flask-migration, Its showing error while migrating i.e on python manage.py db migrate ValueError: invalid interpolation syntax in u'mysql://user:p%40ssword

Alembic/Flask-migrate doesn't recognise database structure

梦想与她 提交于 2019-12-13 20:53:22
问题 I have a Flask-based application and I'm trying to enable migrations to be able to manage database structural changes. My database is not empty and contains tables and records before I started with alembic and flask-migrate. First, I tried to use alembic stand-alone, just pip install alembic and then configure everything and use autogenerate for generating the diff. All works fine but the output was not exactly what I expected: INFO [alembic.autogenerate.compare] Detected removed table u'user

psycopg2.ProgrammingError: relation “event” does not exist

对着背影说爱祢 提交于 2019-12-12 01:17:36
问题 I am using alembic along with flask-migrate along with Postgres for my database. I have ran a db init and db migrate. However when i run the db upgrade command, I get the following error: cursor.execute(statement, parameters) psycopg2.ProgrammingError: relation "event" does not exist The above exception was the direct cause of the following exception: I am very well aware of why the error is happening. The script is trying to create the Attendee table which references an Event table that is

using flask-migrate with flask-script, flask-socketio and application factory

时光怂恿深爱的人放手 提交于 2019-12-07 08:20:49
问题 I'm creating an flask application with the application factory approach, but have an issue when using Flask-Migrate with socketio and flask-script. The problem is that I'm passing my create_app function to the Manager but I need to pass the app to my socketio.run() as well. And right now I can't seem to see a solution. Is there any way I can combine these two solutions? manage.py: #app = create_app(False) <--- Old approach #manager = flask_script.Manager(app) manager = flask_script.Manager

Why is Flask-Migrate making me do a 2-steps migration?

时间秒杀一切 提交于 2019-12-06 02:05:14
问题 I'm working on a project with Flask, SQLAlchemy, Alembic and their wrappers for Flask (Flask-SQLAlchemy and Flask-Migrate). I have four migrations: 1c5f54d4aa34 -> 4250dfa822a4 (head), Feed: Countries 312c1d408043 -> 1c5f54d4aa34, Feed: Continents 41984a51dbb2 -> 312c1d408043, Basic Structure <base> -> 41984a51dbb2, Init Alembic When I start a new and clean database and try to run the migrations I get an error: vagrant@precise32:/vagrant$ python manage.py db upgrade ... sqlalchemy.exc

using flask-migrate with flask-script, flask-socketio and application factory

六月ゝ 毕业季﹏ 提交于 2019-12-05 12:48:05
I'm creating an flask application with the application factory approach, but have an issue when using Flask-Migrate with socketio and flask-script. The problem is that I'm passing my create_app function to the Manager but I need to pass the app to my socketio.run() as well. And right now I can't seem to see a solution. Is there any way I can combine these two solutions? manage.py: #app = create_app(False) <--- Old approach #manager = flask_script.Manager(app) manager = flask_script.Manager(create_app) manager.add_option("-t", "--testing", dest="testing", required=False) manager.add_command(