暗黑模式
Migrations
bash
# 生成一个空的迁移文件
python manage.py makemigrations --empty --name create_superadmin users
# 检测 users 的模型定义是否改变了并自动生成迁移文件
python manage.py makemigrations users
# 应用迁移文件
python manage.py migrate users
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
bash
# 撤销迁移
python manage.py showmigrations users
users
[X] 0001_initial
[X] 0002_create_superadmin
python manage.py migrate users 0001_initial
Operations to perform:
Target specific migration: 0001_initial, from users
Running migrations:
Rendering model states... DONE
Unapplying users.0002_create_superadmin... OK
python manage.py migrate users zero # undo all migrations
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
bash
# 撤销并重置
python manage.py migrate users latest.py
rm migrations/latest.py
python manage.py makemigriaons users
python manage.py migrate users
1
2
3
4
5
2
3
4
5