ProgrammingError: la relación ‘blah blah’ no existe, intentando ejecutar la migración específica y obtener un error

Estoy recibiendo un error:

$ python manage.py migrate swsite 0023_hitcounter.py

 Traceback (most recent call last): File "manage.py", line 10, in  execute_from_command_line(sys.argv) File "/usr/lib64/python2.7/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line utility.execute() File "/usr/lib64/python2.7/site-packages/django/core/management/__init__.py", line 345, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/usr/lib64/python2.7/site-packages/django/core/management/base.py", line 348, in run_from_argv self.execute(*args, **cmd_options) File "/usr/lib64/python2.7/site-packages/django/core/management/base.py", line 398, in execute self.check() File "/usr/lib64/python2.7/site-packages/django/core/management/base.py", line 426, in check include_deployment_checks=include_deployment_checks, File "/usr/lib64/python2.7/site-packages/django/core/checks/registry.py", line 75, in run_checks new_errors = check(app_configs=app_configs) File "/usr/lib64/python2.7/site-packages/django/core/checks/urls.py", line 13, in check_url_config return check_resolver(resolver) File "/usr/lib64/python2.7/site-packages/django/core/checks/urls.py", line 23, in check_resolver for pattern in resolver.url_patterns: File "/usr/lib64/python2.7/site-packages/django/utils/functional.py", line 33, in __get__ res = instance.__dict__[self.name] = self.func(instance) File "/usr/lib64/python2.7/site-packages/django/core/urlresolvers.py", line 417, in url_patterns patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module) File "/usr/lib64/python2.7/site-packages/django/utils/functional.py", line 33, in __get__ res = instance.__dict__[self.name] = self.func(instance) File "/usr/lib64/python2.7/site-packages/django/core/urlresolvers.py", line 410, in urlconf_module return import_module(self.urlconf_name) File "/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module __import__(name) File "/var/www/swlab-website/mysite/urls.py", line 25, in  url(r'^swsite/', include('swsite.urls')), File "/usr/lib64/python2.7/site-packages/django/conf/urls/__init__.py", line 52, in include urlconf_module = import_module(urlconf_module) File "/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module __import__(name) File "/var/www/swlab-website/swsite/urls.py", line 2, in  from . import views File "/var/www/swlab-website/swsite/views.py", line 27, in  class IndexView(generic.ListView): File "/var/www/swlab-website/swsite/views.py", line 31, in IndexView newhit = HitCounter.objects.create() File "/usr/lib64/python2.7/site-packages/django/db/models/manager.py", line 122, in manager_method return getattr(self.get_queryset(), name)(*args, **kwargs) File "/usr/lib64/python2.7/site-packages/django/db/models/query.py", line 401, in create obj.save(force_insert=True, using=self.db) File "/usr/lib64/python2.7/site-packages/django/db/models/base.py", line 708, in save force_update=force_update, update_fields=update_fields) File "/usr/lib64/python2.7/site-packages/django/db/models/base.py", line 736, in save_base updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields) File "/usr/lib64/python2.7/site-packages/django/db/models/base.py", line 820, in _save_table result = self._do_insert(cls._base_manager, using, fields, update_pk, raw) File "/usr/lib64/python2.7/site-packages/django/db/models/base.py", line 859, in _do_insert using=using, raw=raw) File "/usr/lib64/python2.7/site-packages/django/db/models/manager.py", line 122, in manager_method return getattr(self.get_queryset(), name)(*args, **kwargs) File "/usr/lib64/python2.7/site-packages/django/db/models/query.py", line 1039, in _insert return query.get_compiler(using=using).execute_sql(return_id) File "/usr/lib64/python2.7/site-packages/django/db/models/sql/compiler.py", line 1060, in execute_sql cursor.execute(sql, params) File "/usr/lib64/python2.7/site-packages/django/db/backends/utils.py", line 79, in execute return super(CursorDebugWrapper, self).execute(sql, params) File "/usr/lib64/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute return self.cursor.execute(sql, params) File "/usr/lib64/python2.7/site-packages/django/db/utils.py", line 95, in __exit__ six.reraise(dj_exc_type, dj_exc_value, traceback) File "/usr/lib64/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute return self.cursor.execute(sql, params) django.db.utils.ProgrammingError: relation "swsite_hitcounter" does not exist LINE 1: INSERT INTO "swsite_hitcounter" ("date", "template_location"... 

Esto me confunde, ya que está tratando específicamente de construir la tabla swsite_hitcounter como en la siguiente migración que estoy intentando divertir:

 # -*- coding: utf-8 -*- # Generated by Django 1.9.5 on 2017-07-05 15:56 from __future__ import unicode_literals from django.db import migrations, models class Migration(migrations.Migration): dependencies = [ ('swsite', '0022_auto_20170307_1343'), ] operations = [ migrations.CreateModel( name='HitCounter', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('date', models.DateTimeField(auto_now=True)), ('template_location', models.TextField()), ], ), ] 

¿Hay algo tal vez fuera del fregadero? Este soy yo tratando de ejecutar esta migración en mi caja de producción, funcionó bien (por supuesto) en mi caja de desarrollo. ¿Podría haber sido porque ejecuté una migración específica? :

python manage.py migrate swsite 0023_hitcounter.py

    Aunque corriendo

    python manage.py showmigrations

    ¿Me da el mismo error? Supongo que mis migraciones no están sincronizadas pero no puedo mostrar las migraciones, no sé cómo mostrar las que no entraron en esta actualización (en la producción de gilab)

    El rastreo le está mostrando que el error está ocurriendo en IndexView . Está intentando crear objetos en la base de datos cuando se carga la vista.

     class IndexView(TemplateView): newhit = HitCounter.objects.create() # remove this line ... 

    Acceder a la base de datos cuando las vistas se cargan de esta manera es una mala idea, por lo que probablemente debería eliminar la línea. En producción, le da el error porque está intentando crear el objeto en la base de datos antes de que haya aplicado la migración que crea la tabla.