miguelgrinberg/Flask-Migrate
Fork: 229 Star: 2365 (更新于 2024-12-18 09:11:42)
license: MIT
Language: Python .
SQLAlchemy database migrations for Flask applications using Alembic
最后发布版本: v4.0.7 ( 2024-03-12 02:43:03)
Flask-Migrate
Flask-Migrate is an extension that handles SQLAlchemy database migrations for Flask applications using Alembic. The database operations are provided as command-line arguments under the flask db
command.
Installation
Install Flask-Migrate with pip
:
pip install Flask-Migrate
Example
This is an example application that handles database migrations through Flask-Migrate:
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///app.db'
db = SQLAlchemy(app)
migrate = Migrate(app, db)
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(128))
With the above application you can create the database or enable migrations if the database already exists with the following command:
$ flask db init
Note that the FLASK_APP
environment variable must be set according to the Flask documentation for this command to work. This will add a migrations
folder to your application. The contents of this folder need to be added to version control along with your other source files.
You can then generate an initial migration:
$ flask db migrate
The migration script needs to be reviewed and edited, as Alembic currently does not detect every change you make to your models. In particular, Alembic is currently unable to detect indexes. Once finalized, the migration script also needs to be added to version control.
Then you can apply the migration to the database:
$ flask db upgrade
Then each time the database models change repeat the migrate
and upgrade
commands.
To sync the database in another system just refresh the migrations
folder from source control and run the upgrade
command.
To see all the commands that are available run this command:
$ flask db --help
Resources
最近版本更新:(数据更新于 2024-09-18 07:51:25)
2024-03-12 02:43:03 v4.0.7
2024-03-09 19:16:24 v4.0.6
2023-09-12 19:22:09 v4.0.5
2023-08-22 02:50:02 v4.0.4
2023-08-22 02:50:01 v4.0.3
2023-08-22 02:49:59 v4.0.2
2023-08-22 02:49:58 v4.0.1
2023-08-22 02:49:56 v4.0.0
2023-08-22 02:49:55 v3.1.0
2023-08-22 02:49:54 v3.0.1
主题(topics):
alembic, database, flask, migrations, python, sqlalchemy-database-migrations
miguelgrinberg/Flask-Migrate同语言 Python最近更新仓库
2024-12-22 09:03:32 ultralytics/ultralytics
2024-12-21 13:26:40 notepad-plus-plus/nppPluginList
2024-12-21 11:42:53 XiaoMi/ha_xiaomi_home
2024-12-21 04:33:22 comfyanonymous/ComfyUI
2024-12-20 18:47:56 home-assistant/core
2024-12-20 15:41:40 jxxghp/MoviePilot