可根据字段要求设置属性,如字段类型、是否为null
,默认值等
from django.db import models
# Create your models here.
class Case(models.Model):
run_time = models.CharField(max_length=100, default='2022-05-20 13:43:38') # 运行时间点
def __str__(self):
return str(self.id)
#添加迁移事务
python manage.py makemigrations
#将迁移标记为以应用
python manage.py migrate
$ python manage.py makemigrations
Migrations for 'App':
App/migrations/0019_auto_20220520_1510.py
- Alter field run_time on case
$ python manage.py migrate
Operations to perform:
Apply all migrations: App, admin, auth, authtoken, contenttypes, django_cas_ng, sessions
Running migrations:
Applying App.0019_auto_20220520_1510... OK
可以通过 migrate
传递上一次迁移的编号来撤销迁移。
例如,要撤销最近一次迁移 0020_auto_20220520_1511
,进入迁移文件,找到dependencies
中信息
dependencies = [
('App', '0019_auto_20220520_1510'),
]
命令行中执行撤销:
python manage.py migrate App 0019
$ python manage.py migrate App 0019
Operations to perform:
Target specific migration: 0019_auto_20220520_1510, from App
Running migrations:
Rendering model states... DONE
Unapplying App.0020_auto_20220520_1511... OK
python manage.py migrate App zero