djangodjango-models

Django column "name" of relation "django_content_type" does not exist


I keep getting the following error when doing a migration (python manage.py migrate):

django.db.utils.ProgrammingError: column "name" of relation "django_content_type" does not exist

I've done the following to try and fix it but without success:

  1. I've delete all the migrations files for each model
  2. deleted all the records in django_migrations
  3. run python manage.py migrate --fake-initial

Running Django 1.8.2.

python manage.py showmigrations
admin
 [ ] 0001_initial
auth
 [ ] 0001_initial
 [ ] 0002_alter_permission_name_max_length
 [ ] 0003_alter_user_email_max_length
 [ ] 0004_alter_user_username_opts
 [ ] 0005_alter_user_last_login_null
 [ ] 0006_require_contenttypes_0002
contenttypes
 [X] 0001_initial
 [ ] 0002_remove_content_type_name
hashtags
 [ ] 0001_initial
 [ ] 0002_hashtagvisit_user
posts
 [ ] 0001_initial
 [ ] 0002_auto_20150530_0715
sessions
 [ ] 0001_initial
users
 [ ] 0001_initial

Thanks for the help.


Solution

  • Edit 12/2016: I'm recommending this as a workaround, more suited for personal projects or local environments and not production environments. Obviously if you care about your migration history this is not the way to go.

    Encountered this when upgrading to 1.8 and migrating from MySQL to Postgres.

    I can't explain why the error occurs, but I was able to get around it by manually adding the column:

    1. Delete all migrations

    2. Delete records from django_migrations

    3. Manually add name column:

      ALTER TABLE django_content_type ADD COLUMN name character varying(50) NOT NULL DEFAULT 'someName';
      
    4. Run fake initial: $ python manage.py migrate --fake-initial