Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#26246 closed Bug (invalid)

Migrations fail when `'django.contrib.sites'` is included in INSTALLED_APPS

Reported by: Andrew Conti Owned by: nobody
Component: contrib.sites Version: 1.9
Severity: Normal Keywords: sites, migrations, django_site, migrate
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Andrew Conti)

When 'django.contrib.sites' is included in INSTALLED_APPS,

Running:

  python manage.py migrate

fails with:

    django.db.utils.ProgrammingError: relation "django_site" does not exist
    LINE 1: SELECT (1) AS "a" FROM "django_site" LIMIT 1

I have followed the docs and included SITE_ID = 1 in my settings.

Even more puzzling is that when I try to migrate the sites app separately with python manage.py migrate sites it that fails with:

CommandError: App 'sites' does not have migrations

This issue can be reporduced my cloning: https://github.com/agconti/django-contrib-sites-failed-migration-example and running the migrations.

Do you have any idea on way resolve this?

Installed Apps:

INSTALLED_APPS = ( 
 'django.contrib.admin',
  'django.contrib.sites',
  'django.contrib.auth',
  'django.contrib.contenttypes',
  'django.contrib.sessions',
  'django.contrib.messages',
  'django.contrib.staticfiles',
)

Migration error:

(env) ustwo-nyc-conti-mbpr :: ~/dev/test-web » ./test/manage.py migrate                                                                                                        128 ↵
Operations to perform:
  Apply all migrations: admin, contenttypes, auth, sessions
Running migrations:
  No migrations to apply.
Traceback (most recent call last):
  File "./test/manage.py", line 11, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/conti/dev/test-web/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
    utility.execute()
  File "/Users/conti/dev/test-web/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 345, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/conti/dev/test-web/env/lib/python2.7/site-packages/django/core/management/base.py", line 348, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/conti/dev/test-web/env/lib/python2.7/site-packages/django/core/management/base.py", line 399, in execute
docs(README): updated with issue details
    output = self.handle(*args, **options)
  File "/Users/conti/dev/test-web/env/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 204, in handle
    emit_post_migrate_signal(self.verbosity, self.interactive, connection.alias)
  File "/Users/conti/dev/test-web/env/lib/python2.7/site-packages/django/core/management/sql.py", line 50, in emit_post_migrate_signal
    using=db)
  File "/Users/conti/dev/test-web/env/lib/python2.7/site-packages/django/dispatch/dispatcher.py", line 192, in send
    response = receiver(signal=self, sender=sender, **named)
  File "/Users/conti/dev/test-web/env/lib/python2.7/site-packages/django/contrib/sites/management.py", line 20, in create_default_site
    if not Site.objects.using(using).exists():
  File "/Users/conti/dev/test-web/env/lib/python2.7/site-packages/django/db/models/query.py", line 651, in exists
    return self.query.has_results(using=self.db)
  File "/Users/conti/dev/test-web/env/lib/python2.7/site-packages/django/db/models/sql/query.py", line 501, in has_results
    return compiler.has_results()
  File "/Users/conti/dev/test-web/env/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 819, in has_results
    return bool(self.execute_sql(SINGLE))
  File "/Users/conti/dev/test-web/env/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 848, in execute_sql
    cursor.execute(sql, params)
  File "/Users/conti/dev/test-web/env/lib/python2.7/site-packages/django/db/backends/utils.py", line 79, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "/Users/conti/dev/test-web/env/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "/Users/conti/dev/test-web/env/lib/python2.7/site-packages/django/db/utils.py", line 95, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/Users/conti/dev/test-web/env/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: relation "django_site" does not exist
LINE 1: SELECT (1) AS "a" FROM "django_site" LIMIT 1

Change History (4)

comment:1 by Andrew Conti, 8 years ago

Description: modified (diff)

comment:2 by Andrew Conti, 8 years ago

Description: modified (diff)

comment:3 by Tim Graham, 8 years ago

Resolution: invalid
Status: newclosed

You have a custom entry in MIGRATION_MODULES for that app that points to a nonexistent module: 'sites': 'contrib.sites.migrations'.

in reply to:  3 comment:4 by Andrew Conti, 8 years ago

Thank you. This solved my issue.

Replying to timgraham:

You have a custom entry in MIGRATION_MODULES for that app that points to a nonexistent module: 'sites': 'contrib.sites.migrations'.

Note: See TracTickets for help on using tickets.
Back to Top