Django Postgres django.db.utils.ProgrammingError

时间:2017-07-21 17:26:40

标签: python django postgresql

我知道有很多次问过类似的问题,但这些解决方案都没有奏效。

最近,我一直在尝试连接到AWS RDS数据库。但是,现在每当我尝试通过manage.py运行服务器迁移我的数据库时,我总是得到以下结果:

Traceback (most recent call last):
  File "/home/somil/Documents/Twine/venv/lib/python3.4/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
psycopg2.ProgrammingError: relation "employee_employeeprofile" does not exist
LINE 1: ..."employee_employeeprofile"."additional_info" FROM "employee_...
                                                             ^


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

Traceback (most recent call last):
  File "manage.py", line 14, in <module>
    execute_from_command_line(sys.argv)
  File "/home/somil/Documents/Twine/venv/lib/python3.4/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
    utility.execute()
  File "/home/somil/Documents/Twine/venv/lib/python3.4/site-packages/django/core/management/__init__.py", line 327, in execute
    django.setup()
  File "/home/somil/Documents/Twine/venv/lib/python3.4/site-packages/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/home/somil/Documents/Twine/venv/lib/python3.4/site-packages/django/apps/registry.py", line 115, in populate
    app_config.ready()
  File "/home/somil/Documents/Twine/venv/lib/python3.4/site-packages/debug_toolbar/apps.py", line 15, in ready
    dt_settings.patch_all()
  File "/home/somil/Documents/Twine/venv/lib/python3.4/site-packages/debug_toolbar/settings.py", line 228, in patch_all
    patch_root_urlconf()
  File "/home/somil/Documents/Twine/venv/lib/python3.4/site-packages/debug_toolbar/settings.py", line 216, in patch_root_urlconf
    reverse('djdt:render_panel')
  File "/home/somil/Documents/Twine/venv/lib/python3.4/site-packages/django/core/urlresolvers.py", line 568, in reverse
    app_list = resolver.app_dict[ns]
  File "/home/somil/Documents/Twine/venv/lib/python3.4/site-packages/django/core/urlresolvers.py", line 360, in app_dict
    self._populate()
  File "/home/somil/Documents/Twine/venv/lib/python3.4/site-packages/django/core/urlresolvers.py", line 293, in _populate
    for pattern in reversed(self.url_patterns):
  File "/home/somil/Documents/Twine/venv/lib/python3.4/site-packages/django/utils/functional.py", line 33, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/home/somil/Documents/Twine/venv/lib/python3.4/site-packages/django/core/urlresolvers.py", line 417, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/home/somil/Documents/Twine/venv/lib/python3.4/site-packages/django/utils/functional.py", line 33, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/home/somil/Documents/Twine/venv/lib/python3.4/site-packages/django/core/urlresolvers.py", line 410, in urlconf_module
    return import_module(self.urlconf_name)
  File "/home/somil/Documents/Twine/venv/lib/python3.4/importlib/__init__.py", line 109, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1129, in _exec
  File "<frozen importlib._bootstrap>", line 1471, in exec_module
  File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
  File "/home/somil/Documents/Twine/mobility/mobility/urls.py", line 5, in <module>
    from mobility.apps.iam import urls as iam_urls
  File "/home/somil/Documents/Twine/mobility/mobility/apps/iam/urls.py", line 3, in <module>
    from . import views
  File "/home/somil/Documents/Twine/mobility/mobility/apps/iam/views.py", line 7, in <module>
    from ..employee.views import employee_profile
  File "/home/somil/Documents/Twine/mobility/mobility/apps/employee/views.py", line 261, in <module>
    class EmployeeFilter(django_filters.FilterSet):
  File "/home/somil/Documents/Twine/mobility/mobility/apps/employee/views.py", line 267, in EmployeeFilter
    functional_area_name = django_filters.MultipleChoiceFilter(name ="functional_area_name", choices = get_func_names())
  File "/home/somil/Documents/Twine/mobility/mobility/apps/employee/views.py", line 226, in get_func_names
    for e in EmployeeProfile.objects.all():
  File "/home/somil/Documents/Twine/venv/lib/python3.4/site-packages/django/db/models/query.py", line 258, in __iter__
    self._fetch_all()
  File "/home/somil/Documents/Twine/venv/lib/python3.4/site-packages/django/db/models/query.py", line 1074, in _fetch_all
    self._result_cache = list(self.iterator())
  File "/home/somil/Documents/Twine/venv/lib/python3.4/site-packages/django/db/models/query.py", line 52, in __iter__
    results = compiler.execute_sql()
  File "/home/somil/Documents/Twine/venv/lib/python3.4/site-packages/django/db/models/sql/compiler.py", line 848, in execute_sql
    cursor.execute(sql, params)
  File "/home/somil/Documents/Twine/venv/lib/python3.4/site-packages/django/db/backends/utils.py", line 79, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "/home/somil/Documents/Twine/venv/lib/python3.4/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "/home/somil/Documents/Twine/venv/lib/python3.4/site-packages/django/db/utils.py", line 95, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/home/somil/Documents/Twine/venv/lib/python3.4/site-packages/django/utils/six.py", line 685, in reraise
    raise value.with_traceback(tb)
  File "/home/somil/Documents/Twine/venv/lib/python3.4/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: relation "employee_employeeprofile" does not exist
LINE 1: ..."employee_employeeprofile"."additional_info" FROM "employee_...

我尝试删除所有迁移并尝试重新制作,但此错误仍然存​​在。我也在我创建的任何新本地数据库上收到此错误。有什么建议?我觉得我经常会遇到这个错误,而且我可以轻松修复它的唯一方法是删除数据库并再次创建它,但这次它甚至不起作用?

1 个答案:

答案 0 :(得分:0)

您正在调用您的get_func_names()函数,该函数在EmployeeFilter类的类级别查询EmployeeProfile模型。这意味着它在导入时被调用。由于视图是在启动时导入的,因此您的迁移尚未有机会运行。

您不应该在导入时调用任何访问数据库的代码。