Django make migrations issue changing to new Postgres DB












2















I have not been able to find a solution on SO that has worked for me yet, so I figured I would post a question.



I am running into issues migrating a database schema to a new PostgreSQL DB using django.



Here is the connection for my first DB, it works and I am able to run migrations perfectly fine. This is the DB I was using for testing intially, now I want to use a secondary DB and migrate the schema over.



DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'HOST': '[HOST]',
'NAME': 'postgres',
'USER': 'postgres',
'PASSWORD': '[PW]',
}
}


Here is the updated settings:



DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'HOST': '[HOST]',
'NAME': 'test_mh', # this is only difference
'USER': 'postgres',
'PASSWORD': '[PW]',
}
}


I run python3 manage.py makemigrations on the first connection and it is fine.



When I run the same command with the updated DB Name I get exceptions that state my tables do not exist.



  Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
psycopg2.ProgrammingError: relation "objects_community" does not exist
LINE 1: ...y"."state", "objects_community"."date_added" FROM "objects_c...
^


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.6/dist-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.6/dist-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.6/dist-packages/django/core/management/base.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.6/dist-packages/django/core/management/base.py", line 350, in execute
self.check()
File "/usr/local/lib/python3.6/dist-packages/django/core/management/base.py", line 379, in check
include_deployment_checks=include_deployment_checks,
File "/usr/local/lib/python3.6/dist-packages/django/core/management/base.py", line 366, in _run_checks
return checks.run_checks(**kwargs)
File "/usr/local/lib/python3.6/dist-packages/django/core/checks/registry.py", line 71, in run_checks
new_errors = check(app_configs=app_configs)
File "/usr/local/lib/python3.6/dist-packages/django/core/checks/urls.py", line 40, in check_url_namespaces_unique
all_namespaces = _load_all_namespaces(resolver)
File "/usr/local/lib/python3.6/dist-packages/django/core/checks/urls.py", line 57, in _load_all_namespaces
url_patterns = getattr(resolver, 'url_patterns', )
File "/usr/local/lib/python3.6/dist-packages/django/utils/functional.py", line 37, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/usr/local/lib/python3.6/dist-packages/django/urls/resolvers.py", line 533, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/usr/local/lib/python3.6/dist-packages/django/utils/functional.py", line 37, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/usr/local/lib/python3.6/dist-packages/django/urls/resolvers.py", line 526, in urlconf_module
return import_module(self.urlconf_name)
File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/viatech/Projects/ExactEstate/ExactEstate/ExactEstate/urls.py", line 21, in <module>
path('adm/', include('interface_admin.urls')),
File "/usr/local/lib/python3.6/dist-packages/django/urls/conf.py", line 34, in include
urlconf_module = import_module(urlconf_module)
File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/viatech/Projects/ExactEstate/ExactEstate/interface_admin/urls.py", line 2, in <module>
from interface_admin import views
File "/home/viatech/Projects/ExactEstate/ExactEstate/interface_admin/views.py", line 4, in <module>
from forms import RegistrationForm, SQLForm, SingleFileUploadForm, ApartmentTableFormBuilder
File "/home/viatech/Projects/ExactEstate/ExactEstate/forms/ApartmentTableFormBuilder.py", line 10, in <module>
class ApartmentTableFormBuilder(forms.Form):
File "/home/viatech/Projects/ExactEstate/ExactEstate/forms/ApartmentTableFormBuilder.py", line 16, in ApartmentTableFormBuilder
for community in Community.objects.all():
File "/usr/local/lib/python3.6/dist-packages/django/db/models/query.py", line 268, in __iter__
self._fetch_all()
File "/usr/local/lib/python3.6/dist-packages/django/db/models/query.py", line 1186, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "/usr/local/lib/python3.6/dist-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 "/usr/local/lib/python3.6/dist-packages/django/db/models/sql/compiler.py", line 1065, in execute_sql
cursor.execute(sql, params)
File "/usr/local/lib/python3.6/dist-packages/django/db/backends/utils.py", line 100, in execute
return super().execute(sql, params)
File "/usr/local/lib/python3.6/dist-packages/django/db/backends/utils.py", line 68, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/usr/local/lib/python3.6/dist-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/usr/local/lib/python3.6/dist-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "/usr/local/lib/python3.6/dist-packages/django/db/utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/usr/local/lib/python3.6/dist-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: relation "objects_community" does not exist
LINE 1: ...y"."state", "objects_community"."date_added" FROM "objects_c...









share|improve this question



























    2















    I have not been able to find a solution on SO that has worked for me yet, so I figured I would post a question.



    I am running into issues migrating a database schema to a new PostgreSQL DB using django.



    Here is the connection for my first DB, it works and I am able to run migrations perfectly fine. This is the DB I was using for testing intially, now I want to use a secondary DB and migrate the schema over.



    DATABASES = {
    'default': {
    'ENGINE': 'django.db.backends.postgresql',
    'HOST': '[HOST]',
    'NAME': 'postgres',
    'USER': 'postgres',
    'PASSWORD': '[PW]',
    }
    }


    Here is the updated settings:



    DATABASES = {
    'default': {
    'ENGINE': 'django.db.backends.postgresql',
    'HOST': '[HOST]',
    'NAME': 'test_mh', # this is only difference
    'USER': 'postgres',
    'PASSWORD': '[PW]',
    }
    }


    I run python3 manage.py makemigrations on the first connection and it is fine.



    When I run the same command with the updated DB Name I get exceptions that state my tables do not exist.



      Traceback (most recent call last):
    File "/usr/local/lib/python3.6/dist-packages/django/db/backends/utils.py", line 85, in _execute
    return self.cursor.execute(sql, params)
    psycopg2.ProgrammingError: relation "objects_community" does not exist
    LINE 1: ...y"."state", "objects_community"."date_added" FROM "objects_c...
    ^


    The above exception was the direct cause of the following exception:

    Traceback (most recent call last):
    File "manage.py", line 15, in <module>
    execute_from_command_line(sys.argv)
    File "/usr/local/lib/python3.6/dist-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    utility.execute()
    File "/usr/local/lib/python3.6/dist-packages/django/core/management/__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
    File "/usr/local/lib/python3.6/dist-packages/django/core/management/base.py", line 316, in run_from_argv
    self.execute(*args, **cmd_options)
    File "/usr/local/lib/python3.6/dist-packages/django/core/management/base.py", line 350, in execute
    self.check()
    File "/usr/local/lib/python3.6/dist-packages/django/core/management/base.py", line 379, in check
    include_deployment_checks=include_deployment_checks,
    File "/usr/local/lib/python3.6/dist-packages/django/core/management/base.py", line 366, in _run_checks
    return checks.run_checks(**kwargs)
    File "/usr/local/lib/python3.6/dist-packages/django/core/checks/registry.py", line 71, in run_checks
    new_errors = check(app_configs=app_configs)
    File "/usr/local/lib/python3.6/dist-packages/django/core/checks/urls.py", line 40, in check_url_namespaces_unique
    all_namespaces = _load_all_namespaces(resolver)
    File "/usr/local/lib/python3.6/dist-packages/django/core/checks/urls.py", line 57, in _load_all_namespaces
    url_patterns = getattr(resolver, 'url_patterns', )
    File "/usr/local/lib/python3.6/dist-packages/django/utils/functional.py", line 37, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
    File "/usr/local/lib/python3.6/dist-packages/django/urls/resolvers.py", line 533, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
    File "/usr/local/lib/python3.6/dist-packages/django/utils/functional.py", line 37, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
    File "/usr/local/lib/python3.6/dist-packages/django/urls/resolvers.py", line 526, in urlconf_module
    return import_module(self.urlconf_name)
    File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
    File "<frozen importlib._bootstrap>", line 994, in _gcd_import
    File "<frozen importlib._bootstrap>", line 971, in _find_and_load
    File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
    File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
    File "<frozen importlib._bootstrap_external>", line 678, in exec_module
    File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
    File "/home/viatech/Projects/ExactEstate/ExactEstate/ExactEstate/urls.py", line 21, in <module>
    path('adm/', include('interface_admin.urls')),
    File "/usr/local/lib/python3.6/dist-packages/django/urls/conf.py", line 34, in include
    urlconf_module = import_module(urlconf_module)
    File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
    File "<frozen importlib._bootstrap>", line 994, in _gcd_import
    File "<frozen importlib._bootstrap>", line 971, in _find_and_load
    File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
    File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
    File "<frozen importlib._bootstrap_external>", line 678, in exec_module
    File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
    File "/home/viatech/Projects/ExactEstate/ExactEstate/interface_admin/urls.py", line 2, in <module>
    from interface_admin import views
    File "/home/viatech/Projects/ExactEstate/ExactEstate/interface_admin/views.py", line 4, in <module>
    from forms import RegistrationForm, SQLForm, SingleFileUploadForm, ApartmentTableFormBuilder
    File "/home/viatech/Projects/ExactEstate/ExactEstate/forms/ApartmentTableFormBuilder.py", line 10, in <module>
    class ApartmentTableFormBuilder(forms.Form):
    File "/home/viatech/Projects/ExactEstate/ExactEstate/forms/ApartmentTableFormBuilder.py", line 16, in ApartmentTableFormBuilder
    for community in Community.objects.all():
    File "/usr/local/lib/python3.6/dist-packages/django/db/models/query.py", line 268, in __iter__
    self._fetch_all()
    File "/usr/local/lib/python3.6/dist-packages/django/db/models/query.py", line 1186, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
    File "/usr/local/lib/python3.6/dist-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 "/usr/local/lib/python3.6/dist-packages/django/db/models/sql/compiler.py", line 1065, in execute_sql
    cursor.execute(sql, params)
    File "/usr/local/lib/python3.6/dist-packages/django/db/backends/utils.py", line 100, in execute
    return super().execute(sql, params)
    File "/usr/local/lib/python3.6/dist-packages/django/db/backends/utils.py", line 68, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
    File "/usr/local/lib/python3.6/dist-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
    return executor(sql, params, many, context)
    File "/usr/local/lib/python3.6/dist-packages/django/db/backends/utils.py", line 85, in _execute
    return self.cursor.execute(sql, params)
    File "/usr/local/lib/python3.6/dist-packages/django/db/utils.py", line 89, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
    File "/usr/local/lib/python3.6/dist-packages/django/db/backends/utils.py", line 85, in _execute
    return self.cursor.execute(sql, params)
    django.db.utils.ProgrammingError: relation "objects_community" does not exist
    LINE 1: ...y"."state", "objects_community"."date_added" FROM "objects_c...









    share|improve this question

























      2












      2








      2








      I have not been able to find a solution on SO that has worked for me yet, so I figured I would post a question.



      I am running into issues migrating a database schema to a new PostgreSQL DB using django.



      Here is the connection for my first DB, it works and I am able to run migrations perfectly fine. This is the DB I was using for testing intially, now I want to use a secondary DB and migrate the schema over.



      DATABASES = {
      'default': {
      'ENGINE': 'django.db.backends.postgresql',
      'HOST': '[HOST]',
      'NAME': 'postgres',
      'USER': 'postgres',
      'PASSWORD': '[PW]',
      }
      }


      Here is the updated settings:



      DATABASES = {
      'default': {
      'ENGINE': 'django.db.backends.postgresql',
      'HOST': '[HOST]',
      'NAME': 'test_mh', # this is only difference
      'USER': 'postgres',
      'PASSWORD': '[PW]',
      }
      }


      I run python3 manage.py makemigrations on the first connection and it is fine.



      When I run the same command with the updated DB Name I get exceptions that state my tables do not exist.



        Traceback (most recent call last):
      File "/usr/local/lib/python3.6/dist-packages/django/db/backends/utils.py", line 85, in _execute
      return self.cursor.execute(sql, params)
      psycopg2.ProgrammingError: relation "objects_community" does not exist
      LINE 1: ...y"."state", "objects_community"."date_added" FROM "objects_c...
      ^


      The above exception was the direct cause of the following exception:

      Traceback (most recent call last):
      File "manage.py", line 15, in <module>
      execute_from_command_line(sys.argv)
      File "/usr/local/lib/python3.6/dist-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
      utility.execute()
      File "/usr/local/lib/python3.6/dist-packages/django/core/management/__init__.py", line 375, in execute
      self.fetch_command(subcommand).run_from_argv(self.argv)
      File "/usr/local/lib/python3.6/dist-packages/django/core/management/base.py", line 316, in run_from_argv
      self.execute(*args, **cmd_options)
      File "/usr/local/lib/python3.6/dist-packages/django/core/management/base.py", line 350, in execute
      self.check()
      File "/usr/local/lib/python3.6/dist-packages/django/core/management/base.py", line 379, in check
      include_deployment_checks=include_deployment_checks,
      File "/usr/local/lib/python3.6/dist-packages/django/core/management/base.py", line 366, in _run_checks
      return checks.run_checks(**kwargs)
      File "/usr/local/lib/python3.6/dist-packages/django/core/checks/registry.py", line 71, in run_checks
      new_errors = check(app_configs=app_configs)
      File "/usr/local/lib/python3.6/dist-packages/django/core/checks/urls.py", line 40, in check_url_namespaces_unique
      all_namespaces = _load_all_namespaces(resolver)
      File "/usr/local/lib/python3.6/dist-packages/django/core/checks/urls.py", line 57, in _load_all_namespaces
      url_patterns = getattr(resolver, 'url_patterns', )
      File "/usr/local/lib/python3.6/dist-packages/django/utils/functional.py", line 37, in __get__
      res = instance.__dict__[self.name] = self.func(instance)
      File "/usr/local/lib/python3.6/dist-packages/django/urls/resolvers.py", line 533, in url_patterns
      patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
      File "/usr/local/lib/python3.6/dist-packages/django/utils/functional.py", line 37, in __get__
      res = instance.__dict__[self.name] = self.func(instance)
      File "/usr/local/lib/python3.6/dist-packages/django/urls/resolvers.py", line 526, in urlconf_module
      return import_module(self.urlconf_name)
      File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
      return _bootstrap._gcd_import(name[level:], package, level)
      File "<frozen importlib._bootstrap>", line 994, in _gcd_import
      File "<frozen importlib._bootstrap>", line 971, in _find_and_load
      File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
      File "<frozen importlib._bootstrap_external>", line 678, in exec_module
      File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
      File "/home/viatech/Projects/ExactEstate/ExactEstate/ExactEstate/urls.py", line 21, in <module>
      path('adm/', include('interface_admin.urls')),
      File "/usr/local/lib/python3.6/dist-packages/django/urls/conf.py", line 34, in include
      urlconf_module = import_module(urlconf_module)
      File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
      return _bootstrap._gcd_import(name[level:], package, level)
      File "<frozen importlib._bootstrap>", line 994, in _gcd_import
      File "<frozen importlib._bootstrap>", line 971, in _find_and_load
      File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
      File "<frozen importlib._bootstrap_external>", line 678, in exec_module
      File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
      File "/home/viatech/Projects/ExactEstate/ExactEstate/interface_admin/urls.py", line 2, in <module>
      from interface_admin import views
      File "/home/viatech/Projects/ExactEstate/ExactEstate/interface_admin/views.py", line 4, in <module>
      from forms import RegistrationForm, SQLForm, SingleFileUploadForm, ApartmentTableFormBuilder
      File "/home/viatech/Projects/ExactEstate/ExactEstate/forms/ApartmentTableFormBuilder.py", line 10, in <module>
      class ApartmentTableFormBuilder(forms.Form):
      File "/home/viatech/Projects/ExactEstate/ExactEstate/forms/ApartmentTableFormBuilder.py", line 16, in ApartmentTableFormBuilder
      for community in Community.objects.all():
      File "/usr/local/lib/python3.6/dist-packages/django/db/models/query.py", line 268, in __iter__
      self._fetch_all()
      File "/usr/local/lib/python3.6/dist-packages/django/db/models/query.py", line 1186, in _fetch_all
      self._result_cache = list(self._iterable_class(self))
      File "/usr/local/lib/python3.6/dist-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 "/usr/local/lib/python3.6/dist-packages/django/db/models/sql/compiler.py", line 1065, in execute_sql
      cursor.execute(sql, params)
      File "/usr/local/lib/python3.6/dist-packages/django/db/backends/utils.py", line 100, in execute
      return super().execute(sql, params)
      File "/usr/local/lib/python3.6/dist-packages/django/db/backends/utils.py", line 68, in execute
      return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
      File "/usr/local/lib/python3.6/dist-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
      return executor(sql, params, many, context)
      File "/usr/local/lib/python3.6/dist-packages/django/db/backends/utils.py", line 85, in _execute
      return self.cursor.execute(sql, params)
      File "/usr/local/lib/python3.6/dist-packages/django/db/utils.py", line 89, in __exit__
      raise dj_exc_value.with_traceback(traceback) from exc_value
      File "/usr/local/lib/python3.6/dist-packages/django/db/backends/utils.py", line 85, in _execute
      return self.cursor.execute(sql, params)
      django.db.utils.ProgrammingError: relation "objects_community" does not exist
      LINE 1: ...y"."state", "objects_community"."date_added" FROM "objects_c...









      share|improve this question














      I have not been able to find a solution on SO that has worked for me yet, so I figured I would post a question.



      I am running into issues migrating a database schema to a new PostgreSQL DB using django.



      Here is the connection for my first DB, it works and I am able to run migrations perfectly fine. This is the DB I was using for testing intially, now I want to use a secondary DB and migrate the schema over.



      DATABASES = {
      'default': {
      'ENGINE': 'django.db.backends.postgresql',
      'HOST': '[HOST]',
      'NAME': 'postgres',
      'USER': 'postgres',
      'PASSWORD': '[PW]',
      }
      }


      Here is the updated settings:



      DATABASES = {
      'default': {
      'ENGINE': 'django.db.backends.postgresql',
      'HOST': '[HOST]',
      'NAME': 'test_mh', # this is only difference
      'USER': 'postgres',
      'PASSWORD': '[PW]',
      }
      }


      I run python3 manage.py makemigrations on the first connection and it is fine.



      When I run the same command with the updated DB Name I get exceptions that state my tables do not exist.



        Traceback (most recent call last):
      File "/usr/local/lib/python3.6/dist-packages/django/db/backends/utils.py", line 85, in _execute
      return self.cursor.execute(sql, params)
      psycopg2.ProgrammingError: relation "objects_community" does not exist
      LINE 1: ...y"."state", "objects_community"."date_added" FROM "objects_c...
      ^


      The above exception was the direct cause of the following exception:

      Traceback (most recent call last):
      File "manage.py", line 15, in <module>
      execute_from_command_line(sys.argv)
      File "/usr/local/lib/python3.6/dist-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
      utility.execute()
      File "/usr/local/lib/python3.6/dist-packages/django/core/management/__init__.py", line 375, in execute
      self.fetch_command(subcommand).run_from_argv(self.argv)
      File "/usr/local/lib/python3.6/dist-packages/django/core/management/base.py", line 316, in run_from_argv
      self.execute(*args, **cmd_options)
      File "/usr/local/lib/python3.6/dist-packages/django/core/management/base.py", line 350, in execute
      self.check()
      File "/usr/local/lib/python3.6/dist-packages/django/core/management/base.py", line 379, in check
      include_deployment_checks=include_deployment_checks,
      File "/usr/local/lib/python3.6/dist-packages/django/core/management/base.py", line 366, in _run_checks
      return checks.run_checks(**kwargs)
      File "/usr/local/lib/python3.6/dist-packages/django/core/checks/registry.py", line 71, in run_checks
      new_errors = check(app_configs=app_configs)
      File "/usr/local/lib/python3.6/dist-packages/django/core/checks/urls.py", line 40, in check_url_namespaces_unique
      all_namespaces = _load_all_namespaces(resolver)
      File "/usr/local/lib/python3.6/dist-packages/django/core/checks/urls.py", line 57, in _load_all_namespaces
      url_patterns = getattr(resolver, 'url_patterns', )
      File "/usr/local/lib/python3.6/dist-packages/django/utils/functional.py", line 37, in __get__
      res = instance.__dict__[self.name] = self.func(instance)
      File "/usr/local/lib/python3.6/dist-packages/django/urls/resolvers.py", line 533, in url_patterns
      patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
      File "/usr/local/lib/python3.6/dist-packages/django/utils/functional.py", line 37, in __get__
      res = instance.__dict__[self.name] = self.func(instance)
      File "/usr/local/lib/python3.6/dist-packages/django/urls/resolvers.py", line 526, in urlconf_module
      return import_module(self.urlconf_name)
      File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
      return _bootstrap._gcd_import(name[level:], package, level)
      File "<frozen importlib._bootstrap>", line 994, in _gcd_import
      File "<frozen importlib._bootstrap>", line 971, in _find_and_load
      File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
      File "<frozen importlib._bootstrap_external>", line 678, in exec_module
      File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
      File "/home/viatech/Projects/ExactEstate/ExactEstate/ExactEstate/urls.py", line 21, in <module>
      path('adm/', include('interface_admin.urls')),
      File "/usr/local/lib/python3.6/dist-packages/django/urls/conf.py", line 34, in include
      urlconf_module = import_module(urlconf_module)
      File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
      return _bootstrap._gcd_import(name[level:], package, level)
      File "<frozen importlib._bootstrap>", line 994, in _gcd_import
      File "<frozen importlib._bootstrap>", line 971, in _find_and_load
      File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
      File "<frozen importlib._bootstrap_external>", line 678, in exec_module
      File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
      File "/home/viatech/Projects/ExactEstate/ExactEstate/interface_admin/urls.py", line 2, in <module>
      from interface_admin import views
      File "/home/viatech/Projects/ExactEstate/ExactEstate/interface_admin/views.py", line 4, in <module>
      from forms import RegistrationForm, SQLForm, SingleFileUploadForm, ApartmentTableFormBuilder
      File "/home/viatech/Projects/ExactEstate/ExactEstate/forms/ApartmentTableFormBuilder.py", line 10, in <module>
      class ApartmentTableFormBuilder(forms.Form):
      File "/home/viatech/Projects/ExactEstate/ExactEstate/forms/ApartmentTableFormBuilder.py", line 16, in ApartmentTableFormBuilder
      for community in Community.objects.all():
      File "/usr/local/lib/python3.6/dist-packages/django/db/models/query.py", line 268, in __iter__
      self._fetch_all()
      File "/usr/local/lib/python3.6/dist-packages/django/db/models/query.py", line 1186, in _fetch_all
      self._result_cache = list(self._iterable_class(self))
      File "/usr/local/lib/python3.6/dist-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 "/usr/local/lib/python3.6/dist-packages/django/db/models/sql/compiler.py", line 1065, in execute_sql
      cursor.execute(sql, params)
      File "/usr/local/lib/python3.6/dist-packages/django/db/backends/utils.py", line 100, in execute
      return super().execute(sql, params)
      File "/usr/local/lib/python3.6/dist-packages/django/db/backends/utils.py", line 68, in execute
      return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
      File "/usr/local/lib/python3.6/dist-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
      return executor(sql, params, many, context)
      File "/usr/local/lib/python3.6/dist-packages/django/db/backends/utils.py", line 85, in _execute
      return self.cursor.execute(sql, params)
      File "/usr/local/lib/python3.6/dist-packages/django/db/utils.py", line 89, in __exit__
      raise dj_exc_value.with_traceback(traceback) from exc_value
      File "/usr/local/lib/python3.6/dist-packages/django/db/backends/utils.py", line 85, in _execute
      return self.cursor.execute(sql, params)
      django.db.utils.ProgrammingError: relation "objects_community" does not exist
      LINE 1: ...y"."state", "objects_community"."date_added" FROM "objects_c...






      django postgresql django-migrations






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 14 '18 at 16:47









      ViaTechViaTech

      531314




      531314
























          1 Answer
          1






          active

          oldest

          votes


















          2














          The traceback is telling you that your form ApartmentTableFormBuilder is causing a query Community.objects.all() when the module loads.



          When you run migrate or makemigrations on a new database, this causes an error since the objects_community table hasn't been created yet.



          The correct solution is to modify your form so that it doesn't cause any queries when the module loads. A hackier solution would be to temporarily comment out the code that is causing the issue until you have run makemigrations and migrate for the first time.






          share|improve this answer
























          • wonderful the commenting works! The ApartmentTableFormBuilder is a dynamic form used to allow the dynamic (i.e. non-model) creation of Apartment Tables in my DB. In that instance, I am not sure how it would be possible to not call Community.objects.all() as those objects are used to list the names of available Communities in a select option for an HTML form. This is a new feature though, I will look it over and see if I can recode the way things work to 'fix' this issue correctly. Either way, I am good to go now based on your post, so thanks!

            – ViaTech
            Nov 14 '18 at 17:50











          • It should be possible to rearrange your code so that the query does not run when the module loads. I can’t help any more than that because you didn’t show the code in your question.

            – Alasdair
            Nov 14 '18 at 19:18











          • Going to highjack this comment just to ask @Alasdair a question since you seem very knowledgeable about this type of thing. Consider the scenario where you have a big django projects and you have several apps that have models that have foriegn keys in other apps. IE: App1.ModelA has a FK of a model in App2 and App2.ModelB has a FK of a model in App1. What's the best way to deal with this when making migrations for a new DB? It gives circular dependency error if you just try running makemigrations. Thanks.

            – Sam Creamer
            Nov 19 '18 at 20:16













          • @SamCreamer that’s a different problem, it doesn’t belong as a comment on this answer.

            – Alasdair
            Nov 19 '18 at 23:14













          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53305081%2fdjango-make-migrations-issue-changing-to-new-postgres-db%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          The traceback is telling you that your form ApartmentTableFormBuilder is causing a query Community.objects.all() when the module loads.



          When you run migrate or makemigrations on a new database, this causes an error since the objects_community table hasn't been created yet.



          The correct solution is to modify your form so that it doesn't cause any queries when the module loads. A hackier solution would be to temporarily comment out the code that is causing the issue until you have run makemigrations and migrate for the first time.






          share|improve this answer
























          • wonderful the commenting works! The ApartmentTableFormBuilder is a dynamic form used to allow the dynamic (i.e. non-model) creation of Apartment Tables in my DB. In that instance, I am not sure how it would be possible to not call Community.objects.all() as those objects are used to list the names of available Communities in a select option for an HTML form. This is a new feature though, I will look it over and see if I can recode the way things work to 'fix' this issue correctly. Either way, I am good to go now based on your post, so thanks!

            – ViaTech
            Nov 14 '18 at 17:50











          • It should be possible to rearrange your code so that the query does not run when the module loads. I can’t help any more than that because you didn’t show the code in your question.

            – Alasdair
            Nov 14 '18 at 19:18











          • Going to highjack this comment just to ask @Alasdair a question since you seem very knowledgeable about this type of thing. Consider the scenario where you have a big django projects and you have several apps that have models that have foriegn keys in other apps. IE: App1.ModelA has a FK of a model in App2 and App2.ModelB has a FK of a model in App1. What's the best way to deal with this when making migrations for a new DB? It gives circular dependency error if you just try running makemigrations. Thanks.

            – Sam Creamer
            Nov 19 '18 at 20:16













          • @SamCreamer that’s a different problem, it doesn’t belong as a comment on this answer.

            – Alasdair
            Nov 19 '18 at 23:14


















          2














          The traceback is telling you that your form ApartmentTableFormBuilder is causing a query Community.objects.all() when the module loads.



          When you run migrate or makemigrations on a new database, this causes an error since the objects_community table hasn't been created yet.



          The correct solution is to modify your form so that it doesn't cause any queries when the module loads. A hackier solution would be to temporarily comment out the code that is causing the issue until you have run makemigrations and migrate for the first time.






          share|improve this answer
























          • wonderful the commenting works! The ApartmentTableFormBuilder is a dynamic form used to allow the dynamic (i.e. non-model) creation of Apartment Tables in my DB. In that instance, I am not sure how it would be possible to not call Community.objects.all() as those objects are used to list the names of available Communities in a select option for an HTML form. This is a new feature though, I will look it over and see if I can recode the way things work to 'fix' this issue correctly. Either way, I am good to go now based on your post, so thanks!

            – ViaTech
            Nov 14 '18 at 17:50











          • It should be possible to rearrange your code so that the query does not run when the module loads. I can’t help any more than that because you didn’t show the code in your question.

            – Alasdair
            Nov 14 '18 at 19:18











          • Going to highjack this comment just to ask @Alasdair a question since you seem very knowledgeable about this type of thing. Consider the scenario where you have a big django projects and you have several apps that have models that have foriegn keys in other apps. IE: App1.ModelA has a FK of a model in App2 and App2.ModelB has a FK of a model in App1. What's the best way to deal with this when making migrations for a new DB? It gives circular dependency error if you just try running makemigrations. Thanks.

            – Sam Creamer
            Nov 19 '18 at 20:16













          • @SamCreamer that’s a different problem, it doesn’t belong as a comment on this answer.

            – Alasdair
            Nov 19 '18 at 23:14
















          2












          2








          2







          The traceback is telling you that your form ApartmentTableFormBuilder is causing a query Community.objects.all() when the module loads.



          When you run migrate or makemigrations on a new database, this causes an error since the objects_community table hasn't been created yet.



          The correct solution is to modify your form so that it doesn't cause any queries when the module loads. A hackier solution would be to temporarily comment out the code that is causing the issue until you have run makemigrations and migrate for the first time.






          share|improve this answer













          The traceback is telling you that your form ApartmentTableFormBuilder is causing a query Community.objects.all() when the module loads.



          When you run migrate or makemigrations on a new database, this causes an error since the objects_community table hasn't been created yet.



          The correct solution is to modify your form so that it doesn't cause any queries when the module loads. A hackier solution would be to temporarily comment out the code that is causing the issue until you have run makemigrations and migrate for the first time.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 14 '18 at 16:54









          AlasdairAlasdair

          182k26308310




          182k26308310













          • wonderful the commenting works! The ApartmentTableFormBuilder is a dynamic form used to allow the dynamic (i.e. non-model) creation of Apartment Tables in my DB. In that instance, I am not sure how it would be possible to not call Community.objects.all() as those objects are used to list the names of available Communities in a select option for an HTML form. This is a new feature though, I will look it over and see if I can recode the way things work to 'fix' this issue correctly. Either way, I am good to go now based on your post, so thanks!

            – ViaTech
            Nov 14 '18 at 17:50











          • It should be possible to rearrange your code so that the query does not run when the module loads. I can’t help any more than that because you didn’t show the code in your question.

            – Alasdair
            Nov 14 '18 at 19:18











          • Going to highjack this comment just to ask @Alasdair a question since you seem very knowledgeable about this type of thing. Consider the scenario where you have a big django projects and you have several apps that have models that have foriegn keys in other apps. IE: App1.ModelA has a FK of a model in App2 and App2.ModelB has a FK of a model in App1. What's the best way to deal with this when making migrations for a new DB? It gives circular dependency error if you just try running makemigrations. Thanks.

            – Sam Creamer
            Nov 19 '18 at 20:16













          • @SamCreamer that’s a different problem, it doesn’t belong as a comment on this answer.

            – Alasdair
            Nov 19 '18 at 23:14





















          • wonderful the commenting works! The ApartmentTableFormBuilder is a dynamic form used to allow the dynamic (i.e. non-model) creation of Apartment Tables in my DB. In that instance, I am not sure how it would be possible to not call Community.objects.all() as those objects are used to list the names of available Communities in a select option for an HTML form. This is a new feature though, I will look it over and see if I can recode the way things work to 'fix' this issue correctly. Either way, I am good to go now based on your post, so thanks!

            – ViaTech
            Nov 14 '18 at 17:50











          • It should be possible to rearrange your code so that the query does not run when the module loads. I can’t help any more than that because you didn’t show the code in your question.

            – Alasdair
            Nov 14 '18 at 19:18











          • Going to highjack this comment just to ask @Alasdair a question since you seem very knowledgeable about this type of thing. Consider the scenario where you have a big django projects and you have several apps that have models that have foriegn keys in other apps. IE: App1.ModelA has a FK of a model in App2 and App2.ModelB has a FK of a model in App1. What's the best way to deal with this when making migrations for a new DB? It gives circular dependency error if you just try running makemigrations. Thanks.

            – Sam Creamer
            Nov 19 '18 at 20:16













          • @SamCreamer that’s a different problem, it doesn’t belong as a comment on this answer.

            – Alasdair
            Nov 19 '18 at 23:14



















          wonderful the commenting works! The ApartmentTableFormBuilder is a dynamic form used to allow the dynamic (i.e. non-model) creation of Apartment Tables in my DB. In that instance, I am not sure how it would be possible to not call Community.objects.all() as those objects are used to list the names of available Communities in a select option for an HTML form. This is a new feature though, I will look it over and see if I can recode the way things work to 'fix' this issue correctly. Either way, I am good to go now based on your post, so thanks!

          – ViaTech
          Nov 14 '18 at 17:50





          wonderful the commenting works! The ApartmentTableFormBuilder is a dynamic form used to allow the dynamic (i.e. non-model) creation of Apartment Tables in my DB. In that instance, I am not sure how it would be possible to not call Community.objects.all() as those objects are used to list the names of available Communities in a select option for an HTML form. This is a new feature though, I will look it over and see if I can recode the way things work to 'fix' this issue correctly. Either way, I am good to go now based on your post, so thanks!

          – ViaTech
          Nov 14 '18 at 17:50













          It should be possible to rearrange your code so that the query does not run when the module loads. I can’t help any more than that because you didn’t show the code in your question.

          – Alasdair
          Nov 14 '18 at 19:18





          It should be possible to rearrange your code so that the query does not run when the module loads. I can’t help any more than that because you didn’t show the code in your question.

          – Alasdair
          Nov 14 '18 at 19:18













          Going to highjack this comment just to ask @Alasdair a question since you seem very knowledgeable about this type of thing. Consider the scenario where you have a big django projects and you have several apps that have models that have foriegn keys in other apps. IE: App1.ModelA has a FK of a model in App2 and App2.ModelB has a FK of a model in App1. What's the best way to deal with this when making migrations for a new DB? It gives circular dependency error if you just try running makemigrations. Thanks.

          – Sam Creamer
          Nov 19 '18 at 20:16







          Going to highjack this comment just to ask @Alasdair a question since you seem very knowledgeable about this type of thing. Consider the scenario where you have a big django projects and you have several apps that have models that have foriegn keys in other apps. IE: App1.ModelA has a FK of a model in App2 and App2.ModelB has a FK of a model in App1. What's the best way to deal with this when making migrations for a new DB? It gives circular dependency error if you just try running makemigrations. Thanks.

          – Sam Creamer
          Nov 19 '18 at 20:16















          @SamCreamer that’s a different problem, it doesn’t belong as a comment on this answer.

          – Alasdair
          Nov 19 '18 at 23:14







          @SamCreamer that’s a different problem, it doesn’t belong as a comment on this answer.

          – Alasdair
          Nov 19 '18 at 23:14






















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53305081%2fdjango-make-migrations-issue-changing-to-new-postgres-db%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Xamarin.iOS Cant Deploy on Iphone

          Glorious Revolution

          Dulmage-Mendelsohn matrix decomposition in Python