miguelgrinberg/Flask-Migrate
Fork: 227 Star: 2351 (更新于 2024-10-31 08:09:48)
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-11-22 00:03:47 comfyanonymous/ComfyUI
2024-11-21 22:06:18 rashevskyv/dbi
2024-11-21 21:09:02 xtekky/gpt4free
2024-11-21 00:54:04 hect0x7/JMComic-Crawler-Python
2024-11-20 20:44:58 jxxghp/MoviePilot
2024-11-20 12:04:27 GNS3/gns3-gui