2012-01-14 65 views
0

我的models.py:對象沒有被保存,同時使用Django非相對

​​

現在,我想這個代碼在外殼創建項目類對象:

user_object = Users.objects.get(name="abc") 

p = Projects(projectName="xyz",projectManager = user_object) 
p.save() 

項的p .save()它給了我錯誤:

Traceback (most recent call last): 
File "<console>", line 1, in <module> 
File "/home/aprainfo/env/lib/python2.5/site-packages/Django-1.3.1-py2.5.egg/django/db/models/base.py", line 460, in save 
    self.save_base(using=using, force_insert=force_insert, force_update=force_update) 
File "/home/aprainfo/env/lib/python2.5/site-packages/Django-1.3.1-py2.5.egg/django/db/models/base.py", line 543, in save_base 
    for f in meta.local_fields if not isinstance(f, AutoField)] 
File "/home/aprainfo/env/lib/python2.5/site-packages/Django-1.3.1-py2.5.egg/django/db/models/fields/subclassing.py", line 28, in inner 
    return func(*args, **kwargs) 
File "/home/aprainfo/env/lib/python2.5/site-packages/Django-1.3.1-py2.5.egg/django/db/models/fields/related.py", line 876, in get_db_prep_save 
    connection=connection) 
File "/home/aprainfo/env/lib/python2.5/site-packages/Django-1.3.1-py2.5.egg/django/db/models/fields/subclassing.py", line 28, in inner 
    return func(*args, **kwargs) 
File "/home/aprainfo/env/lib/python2.5/site-packages/Django-1.3.1-py2.5.egg/django/db/models/fields/subclassing.py", line 28, in inner 
    return func(*args, **kwargs) 
File "/home/aprainfo/env/lib/python2.5/site-packages/Django-1.3.1-py2.5.egg/django/db/models/fields/__init__.py", line 276, in get_db_prep_save 
    return self.get_db_prep_value(value, connection=connection, prepared=False) 
File "/home/aprainfo/env/lib/python2.5/site-packages/Django-1.3.1-py2.5.egg/django/db/models/fields/subclassing.py", line 53, in inner 
    return func(*args, **kwargs) 
File "/home/aprainfo/env/lib/python2.5/site-packages/Django-1.3.1-py2.5.egg/django/db/models/fields/subclassing.py", line 53, in inner 
    return func(*args, **kwargs) 
File "/home/aprainfo/env/lib/python2.5/site-packages/Django-1.3.1-py2.5.egg/django/db/models/fields/__init__.py", line 271, in get_db_prep_value 
    value = self.get_prep_value(value) 
File "/home/aprainfo/env/lib/python2.5/site-packages/Django-1.3.1-py2.5.egg/django/db/models/fields/__init__.py", line 479, in get_prep_value 
    return int(value) ValueError: invalid literal for int() with base 10: '4f1116115fcff377b2000001' 

我不知道爲什麼它試圖字符串轉換成int類型最後line.I不知道如何GE擺脫這個錯誤?

+0

您正在使用什麼後臺? – 2012-01-14 10:56:09

+0

我正在使用mongoDB與django-mongodb存儲數據 – Anshul 2012-01-14 11:06:39

回答

3

你的問題最有可能與Django的非rel和mongodb引擎的安裝。標準django期望所有的id都是整數,而構成django non-rel的軟件包套件則允許使用mongodb使用的基於字符串的id。

我會建議重新安裝設立繼http://django-mongodb.org/topics/setup.html

定義的順序我有同樣的問題,而且還可能使用標準的Django,而不是非相對一個安裝的問題。

我的點子requirements.txt有這些項:

git+git://github.com/django-nonrel/[email protected] 
git+git://github.com/django-nonrel/[email protected] 
git+git://github.com/django-nonrel/[email protected] 

然後我就能夠做到:pip install -U -r requirements.txt

+0

你救了我的命! – Harry 2012-08-10 13:12:41

+0

也請務必卸載(常規)django,我已經忘記在安裝django-nonrel之前刪除它,並且遇到同樣的問題 – kolba329 2012-08-31 01:32:13

相關問題