我的項目使用Django-1.2.5和Djando-1.3.1正常工作,但與Django-1.4.1不兼容。Django-1.4.1:無法保存對象
我不能夠保存/創建一個對象,並得到一個錯誤下面給出:
from entry.models import Entry
import datetime
from publications.models import Publication
e = Entry(title=u'this is a test headline to test django-1.4.1',
body_html=u'this is a test body data to test django-1.4.1',
pub_date=datetime.datetime.now(),
publication=Publication.objects.get(id=1))
e.save()
錯誤:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/home/admin/banking_code/contify-banking/entry/models.py", line 112, in save
super(Entry, self).save()
File "/home/admin/banking_code/contify-banking/django/db/models/base.py", line 463, in save
self.save_base(using=using, force_insert=force_insert, force_update=force_update)
File "/home/admin/banking_code/contify-banking/django/db/models/base.py", line 551, in save_base
result = manager._insert([self], fields=fields, return_id=update_pk, using=using, raw=raw)
File "/home/admin/banking_code/contify-banking/django/db/models/manager.py", line 203, in _insert
return insert_query(self.model, objs, fields, **kwargs)
File "/home/admin/banking_code/contify-banking/django/db/models/query.py", line 1593, in insert_query
return query.get_compiler(using=using).execute_sql(return_id)
File "/home/admin/banking_code/contify-banking/django/db/models/sql/compiler.py", line 914, in execute_sql
return self.connection.ops.fetch_returned_insert_id(cursor)
File "/home/admin/banking_code/contify-banking/django/db/backends/__init__.py", line 548, in fetch_returned_insert_id
return cursor.fetchone()[0]
TypeError: 'NoneType' object is not subscriptable
任何一個能幫助我嗎?
它是否工作,如果你只是創建一個變量,如在'p = Publication.objects.get(id = 1)',然後在保存您的條目時使用它?無論如何,這似乎是一個更好的方法。 –