Django 1.8 migrate - relation "django_content_type" already exists

13.3k views Asked by At

Any idea why I would be getting this error when I try to migrate?

django.db.utils.ProgrammingError: relation "django_content_type"

I am using using Django 1.8 & PostgreSql

4

There are 4 answers

4
FlipperPA On

You're going to need to use the --fake-initial option when you migrate; it used to be implicit, but has now been made explicit:

https://docs.djangoproject.com/en/1.8/ref/django-admin/#django-admin-option---fake-initial

To quote:

This option is intended for use when first running migrations against a database that preexisted the use of migrations.

Good luck!

2
Andy Baker On

This worked for me:

  1. ./manage.py migrate auth --fake-initial (this throws an error but ignore it)

  2. ./manage.py migrate --fake-initial

0
5280Angel On

@Josh's solution worked for me with the following changes. Prior to step 1, I re-added the missing column:

ALTER TABLE django_content_type ADD COLUMN name character varying(50) NOT NULL DEFAULT 'run migrate.py';

Running python manage.py migrate auth removes this column, presumabley making one or more other changes that failed on some earlier run of migrate.

When running migrate in step 3 I included the --fake-initial flag:

python manage.py migrate --fake-initial

Everything seems to be set right again.

0
Josh On

I, like many, don't really understand the problem. I was able to devise a solution that worked for me.

  1. Comment out all of your custom installed apps. So, you have just the Django stuff.
  2. Migrate only auth: ./manage.py migrate auth
  3. Migrate everything else: ./manage.py migrate
  4. Undo step 1.
  5. Migrate all your apps: ./manage.py migrate.

Good luck!