0
我已經通過PIP安裝django-notifications
通知,添加該應用到我的INSTALLED_APPS
:IntegrityError嘗試發送與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`))')
這是怎麼回事? recipient
和sender
均屬於auth_user
表。任何幫助都感激不盡。
第一個參數應該是收件人,用'演員= sender'或重新順序參數'notify.send(收件人,發件人,動詞=「測試」)' –
@AamirAdnan是不工作要麼。我嘗試'notify.send(recipient,actor = sender,verb ='A test')''然後我得到一個'KeyError'收件人''。如果我使用'notify.send(recipient,sender,verb ='A test')'我得到'TypeError:send()只需要2個參數(給出4)' –
試試這個'notify.send(recipient = recipient,sender =發件人,動詞='一個測試')'這應該工作。 –