zoukankan      html  css  js  c++  java
  • 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='默认值'

  • 相关阅读:
    看代码写程序
    NP
    一道神题
    找平方数
    凝视
    排队打水
    时间计算
    git客户端下载地址
    iOS GCD
    UIView 和 CALayer的那点事
  • 原文地址:https://www.cnblogs.com/RomanticLife/p/8288726.html
Copyright © 2011-2022 走看看