title: django2 migrations ProgrammingError
body: <p>Since I moved from django 1.8 to 2.1 I frequently get db migration errors. It doesn't occur during the migration directly, but when <code>manage.py</code> is called:</p>
  
  <pre><code>django.db.utils.ProgrammingError: relation "obj1_obj2" does not exist
  LINE 1: ....
  </code></pre>
  
  <p>Migration doesn't even start but it defines the relation or any model changes that cause the errors.</p>
  
  <p>When working locally I usually rollback code and then make migrations, but on cloud providers it is useless solution. I work on python 3.6</p>
  
  <p>Full traceback:</p>
  
  <pre><code>Traceback (most recent call last):
    File "./manage.py", line 10, in &lt;module&gt;
      execute_from_command_line(sys.argv)
    File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
      utility.execute()
    File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
      self.fetch_command(subcommand).run_from_argv(self.argv)
    File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 316, in run_from_argv
      self.execute(*args, **cmd_options)
    File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 350, in execute
      self.check()
    File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 379, in check
      include_deployment_checks=include_deployment_checks,
    File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 60, in _run_checks
      issues.extend(super()._run_checks(**kwargs))
    File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 366, in _run_checks
      return checks.run_checks(**kwargs)
    File "/app/.heroku/python/lib/python3.6/site-packages/django/core/checks/registry.py", line 71, in run_checks
      new_errors = check(app_configs=app_configs)
    File "/app/.heroku/python/lib/python3.6/site-packages/django/core/checks/urls.py", line 13, in check_url_config
      return check_resolver(resolver)
    File "/app/.heroku/python/lib/python3.6/site-packages/django/core/checks/urls.py", line 23, in check_resolver
      return check_method()
    File "/app/.heroku/python/lib/python3.6/site-packages/django/urls/resolvers.py", line 396, in check
       for pattern in self.url_patterns:
    File "/app/.heroku/python/lib/python3.6/site-packages/django/utils/functional.py", line 37, in __get__
       res = instance.__dict__[self.name] = self.func(instance)
    File "/app/.heroku/python/lib/python3.6/site-packages/django/urls/resolvers.py", line 533, in url_patterns
       patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
    File "/app/.heroku/python/lib/python3.6/site-packages/django/utils/functional.py", line 37, in __get__
      res = instance.__dict__[self.name] = self.func(instance)
    File "/app/.heroku/python/lib/python3.6/site-packages/django/urls/resolvers.py", line 526, in urlconf_module
       return import_module(self.urlconf_name)
    File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
       return _bootstrap._gcd_import(name[level:], package, level)
    File "&lt;frozen importlib._bootstrap&gt;", line 994, in _gcd_import
    File "&lt;frozen importlib._bootstrap&gt;", line 971, in _find_and_load
    File "&lt;frozen importlib._bootstrap&gt;", line 955, in _find_and_load_unlocked
    File "&lt;frozen importlib._bootstrap&gt;", line 665, in _load_unlocked
    File "&lt;frozen importlib._bootstrap_external&gt;", line 678, in exec_module
    File "&lt;frozen importlib._bootstrap&gt;", line 219, in _call_with_frames_removed
    File "/app/aliz/urls.py", line 8, in &lt;module&gt;
       from camps.urls import api_urlpatterns as camps_api_urlpatterns
    File "/app/camps/urls.py", line 31, in &lt;module&gt;
      path('obecne/', staff_member_required(CurrentEventDetailView.as_view()), {'e_pk': Event.objects.filter(current=True).first().pk}, name='current_camps'),
    File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/query.py", line 605, in first
      for obj in (self if self.ordered else self.order_by('pk'))[:1]:
    File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/query.py", line 268, in __iter__
      self._fetch_all()
    File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/query.py", line 1186, in _fetch_all
      self._result_cache = list(self._iterable_class(self))
    File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/query.py", line 54, in __iter__
      results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
    File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1065, in execute_sql
      cursor.execute(sql, params)
    File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py", line 68, in execute
      return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
    File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
      return executor(sql, params, many, context)
    File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
      return self.cursor.execute(sql, params)
    File "/app/.heroku/python/lib/python3.6/site-packages/django/db/utils.py", line 89, in __exit__
      raise dj_exc_value.with_traceback(traceback) from exc_value
  </code></pre>