Question

I've installed django-notifications via pip, added the app to my INSTALLED_APPS:

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

Updated my URLConf:

import notifications

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

Since I have south installed, I migrate the schema:

$ 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

 ...

Now, I'm trying to manually create a notification via Django shell but I'm getting an 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`))')

What's going on? Both, recipient and sender belong to auth_user table. Any help will be much appreciated.

Was it helpful?

Solution

Ok, I found the problem. For some reason south was using InnoDB storage engine as a default while all my tables have MyISAM as a default. This is how I fixed it:

  1. Drop table notifications_notification
  2. Delete all entries of notifications on south_migrationhistory table so you can migrate notifications again later
  3. Add STORAGE_ENGINE to my database settings:

    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',
            'NAME': 'database',       
            'USER': 'user',           
            'PASSWORD': 'pass',       
            'HOST': '',               
            'PORT': '',               
            'STORAGE_ENGINE': 'MyISAM',
        }
    }
    
  4. Finally, migrate notifications again:

    $ python manage.py migrate notifications
    
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top