python,django,向mysql更新数据时save()报错不能用
水炮 2013-08-08 12:30:54 求大神帮忙,models.py中有个Student类,当我用s = Student(...)创建对象,然后s.save()可以往mysql中插入记录,但是当我用 s.name = 'aaa',想更新的时候,调用s.save()就报错了.错误代码如下,望大家解答一下.
>>> 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
>