2010-02-02 59 views
0

,我發現了錯誤: 異常值:(1110,「列‘關於’指定了兩次」)django.db.models.base.py中的meta.local_fields設置在哪裏?

當我回顧Django的錯誤頁面,我注意到,自定義模式的用戶,似乎是附加到列表兩次。

這似乎是這裏發生在Django/DB /模型/ base.py在base_save():

values = [(f, f.get_db_prep_save(raw and getattr(self, f.attname) or f.pre_save(self, True))) for f in meta.local_fields] 

這是Django的錯誤頁面顯示的值是:

values = [(<django.db.models.fields.CharField object at 0xa78996c>, u'kallie'), 
(<django.db.models.fields.CharField object at 0xa7899cc>, ''), 
(<django.db.models.fields.CharField object at 0xa789a2c>, ''), 
(<django.db.models.fields.EmailField object at 0xa789a8c>, u'[email protected]'), 
(<django.db.models.fields.CharField object at 0xa789b2c>, 'sha1$d4a80$0e5xxxxxxxxxxxxxxxxxxxxddadfb07'), 
(<django.db.models.fields.BooleanField object at 0xa789bcc>, False), 
(<django.db.models.fields.BooleanField object at 0xa789c6c>, True), 
(<django.db.models.fields.BooleanField object at 0xa789d2c>, False), 
(<django.db.models.fields.DateTimeField object at 0xa789dcc>, u'2010-02-03 14:54:35'), 
(<django.db.models.fields.DateTimeField object at 0xa789e2c>, u'2010-02-03 14:54:35'), 
# this is where the values from the User model customizations show up 
(<django.db.models.fields.BooleanField object at 0xa8c69ac>, False), 
(<django.db.models.fields.CharField object at 0xa8c688c>, None), 
(<django.db.models.fields.PositiveIntegerField object at 0xa8c69cc>, 1), 
(<django.db.models.fields.CharField object at 0xa8c69ec>, 'b5ab1603b2308xxxxxxxxxxx75bca1'), 
(<django.db.models.fields.SmallIntegerField object at 0xa8c6dac>, 0), 
(<django.db.models.fields.SmallIntegerField object at 0xa8c6e4c>, 0), 
(<django.db.models.fields.SmallIntegerField object at 0xa8c6e8c>, 0), 
(<django.db.models.fields.SmallIntegerField object at 0xa8c6ecc>, 10), 
(<django.db.models.fields.DateTimeField object at 0xa8c6eec>, u'2010-02-03 14:54:35'), 
(<django.db.models.fields.CharField object at 0xa8c6f2c>, ''), 
(<django.db.models.fields.URLField object at 0xa8c6f6c>, ''), 
(<django.db.models.fields.CharField object at 0xa8c6fac>, ''), 
(<django.db.models.fields.DateField object at 0xa8c6fec>, None), 
(<django.db.models.fields.TextField object at 0xa8cb04c>, ''), 
# at this point User model customizations repeats itself 
(<django.db.models.fields.BooleanField object at 0xa663b0c>, False), 
(<django.db.models.fields.CharField object at 0xaa1e94c>, None), 
(<django.db.models.fields.PositiveIntegerField object at 0xaa1e34c>, 1), 
(<django.db.models.fields.CharField object at 0xaa1e40c>, 'b5ab1603b2308050ebd62f49ca75bca1'), 
(<django.db.models.fields.SmallIntegerField object at 0xa8c6d8c>, 0), 
(<django.db.models.fields.SmallIntegerField object at 0xaa2378c>, 0), 
(<django.db.models.fields.SmallIntegerField object at 0xaa237ac>, 0), 
(<django.db.models.fields.SmallIntegerField object at 0xaa237ec>, 10), 
(<django.db.models.fields.DateTimeField object at 0xaa2380c>, u'2010-02-03 14:54:35'), 
(<django.db.models.fields.CharField object at 0xaa2384c>, ''), 
(<django.db.models.fields.URLField object at 0xaa2388c>, ''), 
(<django.db.models.fields.CharField object at 0xaa238cc>, ''), 
(<django.db.models.fields.DateField object at 0xaa2390c>, None), 
(<django.db.models.fields.TextField object at 0xaa2394c>, '')] 

由於這個應用程序在生產中,我無法弄清楚如何使用pdb.set_trace()來查看save_base中發生了什麼。

到用戶自定義是:

User.add_to_class('email_isvalid', models.BooleanField(default=False)) 
    User.add_to_class('email_key', models.CharField(max_length=16, null=True)) 
    User.add_to_class('reputation', models.PositiveIntegerField(default=1)) 
    User.add_to_class('gravatar', models.CharField(max_length=32)) 
    User.add_to_class('email_feeds', generic.GenericRelation(EmailFeed)) 
    User.add_to_class('favorite_questions', models.ManyToManyField(Question, through=FavoriteQuestion, related_name='favorited_by'))     
    User.add_to_class('badges', models.ManyToManyField(Badge, through=Award, related_name='awarded_to')) 
    User.add_to_class('gold', models.SmallIntegerField(default=0)) 
    User.add_to_class('silver', models.SmallIntegerField(default=0)) 
    User.add_to_class('bronze', models.SmallIntegerField(default=0)) 
    User.add_to_class('questions_per_page', models.SmallIntegerField(choices=QUESTIONS_PER_PAGE_CHOICES, default=10))        
    User.add_to_class('last_seen', models.DateTimeField(default=datetime.datetime.now))      
    User.add_to_class('real_name', models.CharField(max_length=100, blank=True)) 
    User.add_to_class('website', models.URLField(max_length=200, blank=True)) 
    User.add_to_class('location', models.CharField(max_length=100, blank=True)) 
    User.add_to_class('date_of_birth', models.DateField(null=True, blank=True)) 
    User.add_to_class('about', models.TextField(blank=True)) 

Django1.1.1 Python 2.5的

+0

什麼是您的用戶模型的自定義?發佈一些代碼。 – lawrence 2010-02-03 09:30:43

+0

此代碼位於何處?你確定它正在運行兩次? – 2010-02-03 23:06:02

回答

0

我有同樣的問題。在我的情況下,代碼被執行了兩次。我有以下情況:

在一個應用程序:

from apps.accounts.models import User 

而在另一個應用程序:

from accounts.models import User 

自定義代碼是賬戶/ models.py模塊中,它被執行死刑兩次。