0

私はdjango-notificationspip経由でインストールし、アプリを自分に追加しました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シェルを介して手動で通知を作成しようとしていますが、次のようになってい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ます。どんな助けでも大歓迎です。

4

1 に答える 1

0

わかりました、問題が見つかりました。何らかの理由southで、デフォルトとしてInnoDBストレージエンジンを使用していましたが、すべてのテーブルにデフォルトとしてMyISAMがあります。これが私がそれを修正した方法です:

  1. ドロップテーブルnotifications_notification
  2. 後で再度移行できるように、テーブルnotifications上のすべてのエントリを削除しますsouth_migrationhistorynotifications
  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 に答える