请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

You are trying to add a non-nullable field

manage.py@MXol > makemigrations

Tracking file by folder pattern:  migrations

You are trying to add a non-nullable field 'username' to userprofile 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 with a null value for this column)

 2) Quit, and let me add a default in models.py


正在回答 回答被采纳积分+3

1回答

bobby 2018-08-31 10:23:08

你的user这个models截图我看看呢 这个是个提示 比如你在一个一张表中定义了一个字段必能为null 但是因为表中已经存在了数据, 所以你做migrations的时候 django就不知道应该如何处理已有的记录的这个新增的字段怎么办? 你把该字段设置为null=True就行了

0 回复 有任何疑惑可以回复我~
  • 提问者 懒懒喵不吃鱼 #1
    谢谢老师,问题已经解决。username是父类的属性,所以出现问题时比较困惑,后来将migrations下的0001_initial.py删除,重新makemigrations、migrate就好了。
    回复 有任何疑惑可以回复我~ 2018-08-31 16:09:02
  • bobby 回复 提问者 懒懒喵不吃鱼 #2
    好的,
    回复 有任何疑惑可以回复我~ 2018-08-31 17:50:26
问题已解决,确定采纳
还有疑问,暂不采纳
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号