USERS ONLY USER ONLY when using user model, Postgres
I have an application for registering user actions or any actions. So to implement this, I had to use GenericForeignKeys on my model as a number of models could perform actions.
Here's my model:
class Activity(models.Model): actor_content_type = models.ForeignKey( related_name='actor' ) actor_object_id = models.CharField(max_length=500) actor = generic.GenericForeignKey( ct_field='actor_content_type', fk_field='actor_object_id' ) verb = models.CharField(max_length=50)
I can create posts just fine by passing any model instance to "actor", but when I pass django user model instance I get the following error:
self = <django.db.backends.postgresql_psycopg2.base.DatabaseWrapper object at 0x2d3bfd0> def _commit(self): if self.connection is not None: try: > return self.connection.commit() E IntegrityError: insert or update on table "auth_permission" violates foreign key constraint "content_type_id_refs_id_d043b34a" E DETAIL: Key (content_type_id)=(3) is not present in table "django_content_type". /usr/local/lib/python2.7/dist-packages/Django-1.5.10-py2.7.egg/django/db/backends/postgresql_psycopg2/base.py:240: IntegrityError >
Can anyone understand why this is happening?
source to share
In your settings module, change the order of your INSTALLED_APPS variable so that "django.contrib.auth" is below "django.contrib.contenttypes", for example:
INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', ...etc )
INSTALLED_APPS = ( 'django.contrib.contenttypes', 'django.contrib.auth', ...etc )
source to share