Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Django问题:关系;django_现场“;不存在_Python_Django - Fatal编程技术网

Python Django问题:关系;django_现场“;不存在

Python Django问题:关系;django_现场“;不存在,python,django,Python,Django,最近我一直在尝试向我的django网站添加一个站点地图。虽然它在本地服务器上看起来正常,但在上线时返回以下错误: 关系“django_站点”不存在 第1行:…“django_站点”“域”“django_站点”“名称”来自“django_si…” 我一直在尝试很多事情,特别是我在别处看到的迁移技巧,但从未奏效(即使我可能做得不对;我对这一点还不熟悉,也不太放心)。我在尝试加载管理页面时也会遇到同样的错误 我使用的是Python3.7.5,Django版本是2.2.5 以下是我的设置文件的外观: I

最近我一直在尝试向我的django网站添加一个站点地图。虽然它在本地服务器上看起来正常,但在上线时返回以下错误:

关系“django_站点”不存在 第1行:…“django_站点”“域”“django_站点”“名称”来自“django_si…”

我一直在尝试很多事情,特别是我在别处看到的迁移技巧,但从未奏效(即使我可能做得不对;我对这一点还不熟悉,也不太放心)。我在尝试加载管理页面时也会遇到同样的错误

我使用的是Python3.7.5,Django版本是2.2.5

以下是我的设置文件的外观:

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'django.contrib.sitemaps',
'myapp',]

SITE_ID = 1

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',]
以下是有关错误的更多信息:

Traceback:

File "/app/.heroku/python/lib/python3.7/site-packages/django/db/backends/utils.py" in _execute
  84.                 return self.cursor.execute(sql, params)

The above exception (relation "django_site" does not exist
LINE 1: ..."django_site"."domain", "django_site"."name" FROM "django_si...
                                                             ^
) was the direct cause of the following exception:

File "/app/.heroku/python/lib/python3.7/site-packages/django/core/handlers/exception.py" in inner
  34.             response = get_response(request)

File "/app/.heroku/python/lib/python3.7/site-packages/django/core/handlers/base.py" in _get_response
  115.                 response = self.process_exception_by_middleware(e, request)

File "/app/.heroku/python/lib/python3.7/site-packages/django/core/handlers/base.py" in _get_response
  113.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/app/.heroku/python/lib/python3.7/site-packages/django/contrib/sitemaps/views.py" in inner
  16.         response = func(request, *args, **kwargs)

File "/app/.heroku/python/lib/python3.7/site-packages/django/contrib/sitemaps/views.py" in sitemap
  53.     req_site = get_current_site(request)

File "/app/.heroku/python/lib/python3.7/site-packages/django/contrib/sites/shortcuts.py" in get_current_site
  13.         return Site.objects.get_current(request)

File "/app/.heroku/python/lib/python3.7/site-packages/django/contrib/sites/models.py" in get_current
  58.             return self._get_site_by_id(site_id)

File "/app/.heroku/python/lib/python3.7/site-packages/django/contrib/sites/models.py" in _get_site_by_id
  30.             site = self.get(pk=site_id)

File "/app/.heroku/python/lib/python3.7/site-packages/django/db/models/manager.py" in manager_method
  82.                 return getattr(self.get_queryset(), name)(*args, **kwargs)

File "/app/.heroku/python/lib/python3.7/site-packages/django/db/models/query.py" in get
  402.         num = len(clone)

File "/app/.heroku/python/lib/python3.7/site-packages/django/db/models/query.py" in __len__
  256.         self._fetch_all()

File "/app/.heroku/python/lib/python3.7/site-packages/django/db/models/query.py" in _fetch_all
  1242.             self._result_cache = list(self._iterable_class(self))

File "/app/.heroku/python/lib/python3.7/site-packages/django/db/models/query.py" in __iter__
  55.         results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)

File "/app/.heroku/python/lib/python3.7/site-packages/django/db/models/sql/compiler.py" in execute_sql
  1100.             cursor.execute(sql, params)

File "/app/.heroku/python/lib/python3.7/site-packages/django/db/backends/utils.py" in execute
  99.             return super().execute(sql, params)

File "/app/.heroku/python/lib/python3.7/site-packages/django/db/backends/utils.py" in execute
  67.         return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)

File "/app/.heroku/python/lib/python3.7/site-packages/django/db/backends/utils.py" in _execute_with_wrappers
  76.         return executor(sql, params, many, context)

File "/app/.heroku/python/lib/python3.7/site-packages/django/db/backends/utils.py" in _execute
  84.                 return self.cursor.execute(sql, params)

File "/app/.heroku/python/lib/python3.7/site-packages/django/db/utils.py" in __exit__
  89.                 raise dj_exc_value.with_traceback(traceback) from exc_value

File "/app/.heroku/python/lib/python3.7/site-packages/django/db/backends/utils.py" in _execute
  84.                 return self.cursor.execute(sql, params)

Exception Type: ProgrammingError at /sitemap.xml
Exception Value: relation "django_site" does not exist
LINE 1: ..."django_site"."domain", "django_site"."name" FROM "django_si...
                                                             ^
此外,我还尝试执行了一次迁移,以防万一(因此删除了migrations文件夹中的pycache文件夹,删除了数据库,然后使用命令行运行了一次新的迁移:python manage.py migrate)。看起来一切正常。不过,我必须补充一点,我的迁移文件夹大部分是空的。我只有init.py文件和pycache文件夹,其中只包含一个名为init.cpython-37.pyc的文件。这正常吗

如果你需要更多的细节,请告诉我


提前感谢!

好的,所以我设法找到了问题的原因。我以为我已经做了,但显然没有。我遇到了一个类似的问题,人们只需注释掉“'django.contrib.sites”,“在设置文件中。这样做可以加载站点地图和管理页面。

请提供整个堆栈跟踪。嗨@Shashank Singh,我已经编辑了我的初始帖子。我希望它会有用。谢谢你确定你的迁移成功了吗??显示数据库中的表列表…问题是我没有真正使用数据库。我有一个小的db.sqlite3文件,但它是自动创建的。我从来没有用它来存储特定的数据。我试图用sqlite查看器查看其内容,但它只返回了0个结果的查询:选择“auth_group”中的*限制0,30请参考链接并将结果粘贴到此处。