我已经django-notifications
通过 pip 安装,将应用程序添加到我的INSTALLED_APPS
:
INSTALLED_APPS = (
'django.contrib.auth',
...
'notifications',
...
)
更新了我的 URLConf:
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 shell 手动创建通知,但我得到了一个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
。任何帮助都感激不尽。