I always put it into 4-step are:
安装、配置、创建(仓库、脚本)、更新
as follows
Flask-Migrate to achieve database migration
A mounting Flask-Migrate
pip install flask-migrate
If the installation appears ReadTimeoutError
can refer to: select domestic Mirror
Second, the configuration Flask-Migrate
from flask_migrate import Migrate, MigrateCommand
migrate = Migrate(app, db)
manager.add_command('db', MigrateCommand)
Third, create (warehouses, script)
Create create a migration into the warehouse now create migration scripts as follows:
1. Create a warehouse migration
python manage.py db init
Which manage.py for your startup files
And return to something like the following directories appear migrations (for storing the migration script) folder, even if successful it!
Creating directory /home/flask/flasky/migrations...done
Creating directory /home/flask/flasky/migrations/versions...done
Generating /home/flask/flasky/migrations/alembic.ini...done
Generating /home/flask/flasky/migrations/env.py...done
Generating /home/flask/flasky/migrations/env.pyc...done
Generating /home/flask/flasky/migrations/README...done
Generating /home/flask/flasky/migrations/script.py.mako...done
Please edit configuration/connection/logging settings in
2. Creating migration scripts
python manage.py db migrate -m "initial migration"
After -m quotes the content of the remark can be changed to suit your requirements
The successful return to something like the following
INFO [alembic.migration] Context impl SQLiteImpl.
INFO [alembic.migration] Will assume non-transactional DDL.
INFO [alembic.autogenerate] Detected added table 'roles'
INFO [alembic.autogenerate] Detected added table 'users'
INFO [alembic.autogenerate.compare] Detected added index
'ix_users_username' on '['username']'
Generating /home/flask/flasky/migrations/versions/1bc
594146bb5_initial_migration.py...done
Fifth, to update the database
python manage.py db upgrade
The successful return to something like the following
INFO [alembic.migration] Context impl SQLiteImpl.
INFO [alembic.migration] Will assume non-transactional DDL.
INFO [alembic.migration] Running upgrade None -> 1bc594146bb5, initial migration
End: Meng as a new, all aspects of their capabilities are still inadequate, so inevitably there are mistakes, correct me hope Gangster pay more. If you have this blog to help you feel small or 7 written also possible, please give 7 small
点个赞吧!
power every praise all my efforts forward to! Thank you!