2012-12-28 36 views
0

我已經通過PIP安裝django-notifications通知,添加該應用到我的INSTALLED_APPSIntegrityError嘗試發送與Django的通知

INSTALLED_APPS = (
    'django.contrib.auth', 
    ... 
    'notifications', 
    ... 
) 

更新我的URL配置:

import notifications 

urlpatterns = patterns('', 
    ... 
    ('^inbox/notifications/', include(notifications.urls), namespace='notifications'), 
    ... 
) 

因爲我有south已安裝,我遷移架構:

$ python manage.py migrate notifications 
... 
... 

$ python manage.py migrate --list 

notifications 
    (*) 0001_initial 
    (*) 0002_auto__add_field_notification_data 
    (*) 0003_auto__add_field_notification_unread 
    (*) 0004_convert_readed_to_unread 
    (*) 0005_auto__del_field_notification_readed 
    (*) 0006_auto__add_field_notification_level 

... 

現在,我試圖手動創建通過Django的殼的通知,但我發現了一個IntegrityError

[1]: from django.contrib.auth.models import User 

[2]: from notifications import notify 

[3]: recipient = User.objects.get(username="admin") 

[4]: sender = User.objects.get(username="guest") 

[5]: notify.send(sender, verb='A test', recipient=recipient) 
... 
... 
... 
IntegrityError: (1452, 'Cannot add or update a child row: a foreign key constraint fails (`myapp`.`notifications_notification`, CONSTRAINT `recipient_id_refs_id_5c79cb54` FOREIGN KEY (`recipient_id`) REFERENCES `auth_user` (`id`))') 

這是怎麼回事? recipientsender均屬於auth_user表。任何幫助都感激不盡。

+0

第一個參數應該是收件人,用'演員= sender'或重新順序參數'notify.send(收件人,發件人,動詞=「測試」)' –

+0

@AamirAdnan是不工作要麼。我嘗試'notify.send(recipient,actor = sender,verb ='A test')''然後我得到一個'KeyError'收件人''。如果我使用'notify.send(recipient,sender,verb ='A test')'我得到'TypeError:send()只需要2個參數(給出4)' –

+0

試試這個'notify.send(recipient = recipient,sender =發件人,動詞='一個測試')'這應該工作。 –

回答

0

好吧,我發現了這個問題。出於某種原因,south使用InnoDB存儲引擎作爲默認值,而我的所有表都將MyISAM作爲默認值。這是我如何固定它:

  1. DROP TABLE notifications_notification
  2. 刪除對south_migrationhistory表的notifications所有條目,因此您可以再次遷移notifications後來
  3. 添加STORAGE_ENGINE到我的數據庫設置:

    DATABASES = { 
        'default': { 
         'ENGINE': 'django.db.backends.mysql', 
         'NAME': 'database',  
         'USER': 'user',   
         'PASSWORD': 'pass',  
         'HOST': '',    
         'PORT': '',    
         'STORAGE_ENGINE': 'MyISAM', 
        } 
    } 
    
  4. 最後再遷移notifications

    $ python manage.py migrate notifications