• Django中关于MySQL的bug总结


    bug one:

    You are trying to add a non-nullable field 'height' to person without a default; we can't 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)
    2) Quit, and let me add a default in models.py

    问题描述:当数据库表已经建立完成之后,再往models.py该表格所对应的类中再次添加新的字段,然后执行python manage.py makemigrations时,就会产生该bug。

    具体原因:当我们创建表完成后,Django会默认觉得我们已经往表中添加了数据。当添加了一个新的字段的时候,表中已经存在的记录也都同时多了这个新添加的字段,但是赋给这个字段什么值Django不知道怎么办了,所以我们需要给这个新字段添加一个默认值。

    解决办法:

    1.

    You are trying to add a non-nullable field 'height' to person without a default; we can't 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)
    2) Quit, and let me add a default in models.py
    Select an option: 2   这里选择2 

    2.刚才新添加的字段给个默认值。default='默认值'

  • 相关阅读:
    支持向量机SVM知识点概括
    决策树知识点概括
    HDU 3081 Marriage Match II
    HDU 3572 Task Schedule
    HDU 4888 Redraw Beautiful Drawings
    Poj 2728 Desert King
    HDU 3926 Hand in Hand
    HDU 1598 find the most comfortable road
    HDU 4393 Throw nails
    POJ 1486 Sorting Slides
  • 原文地址:https://www.cnblogs.com/RomanticLife/p/8288726.html
Copyright © 2020-2023  润新知