>>> s.save()
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "D:\Program Files (x86)\Python27\lib\site-packages\django\db\models\base.
py", line 431, in save
self.save_base(force_insert=force_insert, force_update=force_update)
File "D:\Program Files (x86)\Python27\lib\site-packages\django\db\models\base.
py", line 495, in save_base
rows = manager.filter(pk=pk_val)._update(values)
File "D:\Program Files (x86)\Python27\lib\site-packages\django\db\models\query
.py", line 446, in _update
query.add_update_fields(values)
File "D:\Program Files (x86)\Python27\lib\site-packages\django\db\models\sql\s
ubqueries.py", line 249, in add_update_fields
val = field.get_db_prep_save(val)
File "D:\Program Files (x86)\Python27\lib\site-packages\django\db\models\field
s\__init__.py", line 202, in get_db_prep_save
return self.get_db_prep_value(value)
File "D:\Program Files (x86)\Python27\lib\site-packages\django\db\models\field
s\__init__.py", line 446, in get_db_prep_value
return self.to_python(value)
File "D:\Program Files (x86)\Python27\lib\site-packages\django\db\models\field
s\__init__.py", line 442, in to_python
ugettext_lazy("This field cannot be null."))
ValidationError: <django.utils.functional.__proxy__ object at 0x0000000002F26320
>
2 个解决方案
#1
你调用save的时候,有的字段值为空了,建议用下面的update方法
ModelName.objects.filter(id=1).update(name='aaa')
ModelName.objects.filter(id=1).update(name='aaa')
#2
贴一些代码吧,感觉好像是你的model object已经离开了执行的上下文
#1
你调用save的时候,有的字段值为空了,建议用下面的update方法
ModelName.objects.filter(id=1).update(name='aaa')
ModelName.objects.filter(id=1).update(name='aaa')
#2
贴一些代码吧,感觉好像是你的model object已经离开了执行的上下文