码迷,mamicode.com
首页 > 编程语言 > 详细

python manage.py makemigrat Please select a fix: 1) Provide a one-off default now (will be set on all existing rows with a null value for this column) 2) Quit, and let me add a default in models.py

时间:2019-12-06 11:22:20      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:you   原因   pps   blank   quit   mamicode   shu   please   执行   

更新models字段

技术图片

 

 

出现的问题:

$ python manage.py makemigrations
None
You are trying to add a non-nullable field file_type to filejinja without a default; we cant do that (the database needs something to populate existing rows).
Please select a fix:
 1) Provide a one-off default now (will be set on all existing rows with a null value for this column)
 2) Quit, and let me add a default in models.py
Select an option:

 

原因:

技术图片

之前数据表里面已经存在,如果添加,file_type需要默认值

 

 

 

解决:

方法1:

 在model字段后面添加,

 blank=True, null=True
    file_type = models.CharField(verbose_name="文件type", max_length=1, choices=(
        (1, "配置文件"),
        (2, "sls文件"),
    ), blank=True, null=True)

 

再执行

$ python manage.py makemigrations
None
Migrations for minions:
  apps\minions\migrations\0011_filejinja_file_type.py
    - Add field file_type to filejinja

 技术图片

 

方法2:

数据库中找到django_migrations,该表对应,每次makemigrations的每次记录

技术图片

 

 删除,生成的migrations

在删除你要更新的表。

技术图片

 

 

重新生成新的表

$ python manage.py makemigrations
None
Migrations for minions:
  apps\minions\migrations\0010_filejinja.py
    - Create model FileJinja

liangshuo@zt-2013326 MINGW64 /f/11_goms/goms (master)
$ python manage.py migrate
None
Operations to perform:
  Apply all migrations: admin, auth, contenttypes, minions, salt, sessions
Running migrations:
  Applying minions.0010_filejinja... OK

 

技术图片

 

python manage.py makemigrat Please select a fix: 1) Provide a one-off default now (will be set on all existing rows with a null value for this column) 2) Quit, and let me add a default in models.py

标签:you   原因   pps   blank   quit   mamicode   shu   please   执行   

原文地址:https://www.cnblogs.com/venicid/p/11993861.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!