CommandError: notifications.notification: 'recipient defines a relation with the model 'auth.User'

StackOverflow https://stackoverflow.com/questions/23616901

  •  21-07-2023
  •  | 
  •  

Question

I've been working on a Django project for a while in Eclipse. I'm using the django-notifications library which has been working fine in Eclipse.

However, when I tried to build the project outside of Eclipse, I got this error:

   CommandError: One or more models did not validate:
   notifications.notification: 'recipient' defines a relation with the model            
   'auth.User', which has been swapped out. Update the relation to point at settings.AUTH_USER_MODEL.

This has been bothering me for quite some time now.

I've had a look at questions similar to this one on StackOverflow but none of them have had a solution that worked.

I'm confused as to why this worked in Eclipse but not from the terminal.

This is my custom User model which seems to be causing a problem:

class User(AbstractUser):

coins = models.IntegerField(default=0)
rating = models.IntegerField(default=0)

profile_picture = models.ImageField(upload_to=upload_to)

And then this is the setting in settings.py: (The app is also called User)

AUTH_USER_MODEL = 'User.User'

Why is this error happening and how do I fix it?

Was it helpful?

Solution

in django-notifications 0.6.0 https://github.com/brantyoung/django-notifications/blob/0.6/notifications/models.py:

recipient = models.ForeignKey(User, blank=False, related_name='notifications')

line 87. Recipient refers auth.User, not your custom user

You need version 0.6.2 or 0.6.1

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top