You are trying to add the field 'create_time' with 'auto_now_add=True' to video without a default; the database needs something to populate existing
rows.
1) Provide a one-off default now (will be set on all existing rows)
2) Quit, and let me add a default in models.py
Select an option: 1
这段话的意思是 pub_date 字段没有默认值,而且非Null 那么
1) 指定一个一次性的值供更改数据库时使用。
2) 停止当前操作,在 models.py 中给定默认值,然后再来migrate。
我们选择第一个,输入 1
Please enter the default value now, as valid Python
You can accept the default 'timezone.now' by pressing 'Enter' or you can provide another value.
The datetime and django.utils.timezone modules are available, so you can do e.g. timezone.now
Type 'exit' to exit this prompt
[default: timezone.now] >>> timezone.now()
Migrations for 'video':
video\migrations\0005_video_create_time.py
- Add field create_time to video
这样是生成了一个对表进行更改的 py 文件在 news/migrations 文件夹中,我们要执行更改
1python manage.py migrate 或 python manage.py migrate news
(video2) D:\2019\video2>python manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, comment, contenttypes, sessions, thumbnail, users, video
Running migrations:
Applying video.0005_video_create_time... OK
网友评论