django.db.utils.ProgrammingError:关系“ django_content_type”不存在

时间:2018-10-10 17:23:13

标签: django

我有一个在PC上缓慢建立的项目,它运行正常。我只是想将其放到服务器上,但出现此错误:

  

django.db.utils.ProgrammingError:关系“ django_content_type”确实   不存在

我无法解决该问题,Stackoverflow上的帖子建议删除并重新创建迁移,我做了,但是存在相同的问题。如果您能指导我寻找的东西,我将不胜感激。

这是我的追踪记录:

Traceback (most recent call last):
  File "manage.py", line 15, in <module>
    execute_from_command_line(sys.argv)
  File "/var/www/jobsite/env/lib/python3.5/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
    utility.execute()
  File "/var/www/jobsite/env/lib/python3.5/site-packages/django/core/management/__init__.py", line 365, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/var/www/jobsite/env/lib/python3.5/site-packages/django/core/management/base.py", line 288, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/var/www/jobsite/env/lib/python3.5/site-packages/django/core/management/base.py", line 332, in execute
    self.check()
  File "/var/www/jobsite/env/lib/python3.5/site-packages/django/core/management/base.py", line 364, in check
    include_deployment_checks=include_deployment_checks,
  File "/var/www/jobsite/env/lib/python3.5/site-packages/django/core/management/commands/migrate.py", line 58, in _run_checks
    issues.extend(super()._run_checks(**kwargs))
  File "/var/www/jobsite/env/lib/python3.5/site-packages/django/core/management/base.py", line 351, in _run_checks
    return checks.run_checks(**kwargs)
  File "/var/www/jobsite/env/lib/python3.5/site-packages/django/core/checks/registry.py", line 73, in run_checks
    new_errors = check(app_configs=app_configs)
  File "/var/www/jobsite/env/lib/python3.5/site-packages/django/core/checks/urls.py", line 40, in check_url_namespaces_unique
    all_namespaces = _load_all_namespaces(resolver)
  File "/var/www/jobsite/env/lib/python3.5/site-packages/django/core/checks/urls.py", line 57, in _load_all_namespaces
    url_patterns = getattr(resolver, 'url_patterns', [])
  File "/var/www/jobsite/env/lib/python3.5/site-packages/django/utils/functional.py", line 36, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/var/www/jobsite/env/lib/python3.5/site-packages/django/urls/resolvers.py", line 540, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/var/www/jobsite/env/lib/python3.5/site-packages/django/utils/functional.py", line 36, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/var/www/jobsite/env/lib/python3.5/site-packages/django/urls/resolvers.py", line 533, in urlconf_module
    return import_module(self.urlconf_name)
  File "/var/www/jobsite/env/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 665, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/var/www/jobsite/jobsite/urls.py", line 32, in <module>
    path('', include('user_management.urls')),
  File "/var/www/jobsite/env/lib/python3.5/site-packages/django/urls/conf.py", line 34, in include
    urlconf_module = import_module(urlconf_module)
  File "/var/www/jobsite/env/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 665, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/var/www/jobsite/user_management/urls.py", line 3, in <module>
    from user_management import views
  File "/var/www/jobsite/user_management/views.py", line 11, in <module>
    from user_management.forms import ApplicantSignUpForm, CompanySignUpForm, CompanyUserSignUpForm, ApplicationForm
  File "/var/www/jobsite/user_management/forms.py", line 82, in <module>
    class ApplicationForm(forms.ModelForm):
  File "/var/www/jobsite/env/lib/python3.5/site-packages/django/forms/models.py", line 256, in __new__
    apply_limit_choices_to=False,
  File "/var/www/jobsite/env/lib/python3.5/site-packages/django/forms/models.py", line 172, in fields_for_model
    formfield = f.formfield(**kwargs)
  File "/var/www/jobsite/env/lib/python3.5/site-packages/django/db/models/fields/related.py", line 953, in formfield
    'queryset': self.remote_field.model._default_manager.using(using),
  File "/var/www/jobsite/env/lib/python3.5/site-packages/django/db/models/manager.py", line 82, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/var/www/jobsite/env/lib/python3.5/site-packages/secretballot/__init__.py", line 59, in get_queryset
    content_type = ContentType.objects.get_for_model(self.model).id
  File "/var/www/jobsite/env/lib/python3.5/site-packages/django/contrib/contenttypes/models.py", line 51, in get_for_model
    ct = self.get(app_label=opts.app_label, model=opts.model_name)
  File "/var/www/jobsite/env/lib/python3.5/site-packages/django/db/models/manager.py", line 82, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/var/www/jobsite/env/lib/python3.5/site-packages/django/db/models/query.py", line 397, in get
    num = len(clone)
  File "/var/www/jobsite/env/lib/python3.5/site-packages/django/db/models/query.py", line 254, in __len__
    self._fetch_all()
  File "/var/www/jobsite/env/lib/python3.5/site-packages/django/db/models/query.py", line 1179, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
  File "/var/www/jobsite/env/lib/python3.5/site-packages/django/db/models/query.py", line 53, in __iter__
    results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
  File "/var/www/jobsite/env/lib/python3.5/site-packages/django/db/models/sql/compiler.py", line 1068, in execute_sql
    cursor.execute(sql, params)
  File "/var/www/jobsite/env/lib/python3.5/site-packages/django/db/backends/utils.py", line 68, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/var/www/jobsite/env/lib/python3.5/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/var/www/jobsite/env/lib/python3.5/site-packages/django/db/backends/utils.py", line 85, in _execute
    return self.cursor.execute(sql, params)
  File "/var/www/jobsite/env/lib/python3.5/site-packages/django/db/utils.py", line 89, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/var/www/jobsite/env/lib/python3.5/site-packages/django/db/backends/utils.py", line 85, in _execute
    return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: relation "django_content_type" does not exist
LINE 1: ..."."app_label", "django_content_type"."model" FROM "django_co...

EDIT添加了ApplicationForm

class ApplicationForm(forms.ModelForm):
    class Meta:
        model = Application
        exclude = ['applied_at']

        widgets = {
            'job' : forms.HiddenInput(),
            'user' : forms.HiddenInput(),
            'apply_name' :forms.TextInput(attrs={ "class" : 'form-control'}),
            'apply_email' : forms.EmailInput(attrs={ "class" : 'form-control'}),
            'apply_cv' : forms.FileInput(attrs={'class' : 'form-control', 
                                            'id' : 'input-file'}),
            'ip_address' : forms.HiddenInput()
        }

1 个答案:

答案 0 :(得分:0)

Alain对它进行了排序。

这是在第一次迁移时发生的。

问题是urls.py

url_patterns = [...]包围在try-Except构造中,并在Exception部分中设置urlpatterns = []。您的错误可能正在发生,因为您的代码正试图对尚未建立的数据库执行操作。