0

我已经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属于senderauth_user。任何帮助都感激不尽。

4

1 回答 1

0

好的,我发现了问题。出于某种原因south,默认使用 InnoDB 存储引擎,而我所有的表都默认使用 MyISAM。这就是我修复它的方法:

  1. 删除表notifications_notification
  2. notifications删除on table的所有条目,south_migrationhistory以便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
    
于 2013-01-02T15:23:51.160 回答