Django ‘columns app_label, model are not unique’
Posted on 19. Nov, 2011 by jason in code
Occasionally while installing fixtures with Django, you might find yourself running into this error:
IntegrityError: columns app_label, model are not unique
What is happening is you’re trying to install a fixture for a model(/table) that django has already dynamically created data for. This is usually either the django_content_types table, or auth_users.
One way to fix this is to omit these from your datadump like so:
python manage.py dumpdata --format=json --exclude=contenttypes
That’s all well and good unless you have things like GenericForeignKeys that need to match up with the content-types and data. To get around this, just delete the content types you don’t want after you syncdb and make any migrations. (Note: Depending on your circumstance, you may want to exclude and/or delete the auth stuff as well)
$ python manage.py syncdb
$ python manage.py migrate
sqlite> delete from django_content_type where 1=1;
Now that those are out of the way, feel free to load your data without any errors.
$ python manage.py loaddata dev_data.json
Installed 6470 object(s) from 1 fixture(s)
