Python Django:关系“django_site”不存在

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23925726/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 03:42:05  来源:igfitidea点击:

Django: relation "django_site" does not exist

pythondjango

提问by JohnnyWineShirt

I am running a test django server on aws and I just installed django-userena and when I try to signup a user upon clicking submit, I get the following message:

我正在 aws 上运行测试 django 服务器,我刚刚安装了 django-userena,当我尝试在单击提交时注册用户时,我收到以下消息:

relation "django_site" does not exist LINE 1: ..."django_site"."domain", "django_site"."name" FROM "django_si...

关系“django_site”不存在第 1 行:...“django_site”.“domain”、“django_site”.“name” FROM “django_si...

I am not really sure what went wrong here. I did some researching and added " 'django.contrib.sites',"to my installed apps, but I am still getting the error. I will there is an extra step I am missing. Any suggestions or advice?

我不确定这里出了什么问题。我做了一些研究并添加" 'django.contrib.sites',"到我安装的应用程序中,但我仍然收到错误消息。我会缺少一个额外的步骤。有什么建议或意见吗?

采纳答案by Franey

I recently ran into this issue (Django 1.8.7) even with SITE_ID = 1in my settings. I had to manually migrate the sitesapp before any other migrations:

即使SITE_ID = 1在我的设置中,我最近也遇到了这个问题(Django 1.8.7)。我必须sites在任何其他迁移之前手动迁移应用程序:

./manage.py migrate sites
./manage.py migrate

回答by Geo Jacob

You may be calling a site object before creating site model(before syncdb or migrate)

您可能在创建站点模型之前调用站点对象(在同步数据库或迁移之前)

ex: site = Site.objects.get(id=settings.SITE_ID)

例如:站点 = Site.objects.get(id=settings.SITE_ID)

回答by Saeed Gharedaghi

I have the same problem and fixed it like this:

我有同样的问题并像这样修复它:

  1. add SITE_ID=1into settings.py
  2. run this command :

    python manage.py migrate
    
  1. 添加SITE_ID=1settings.py
  2. 运行这个命令:

    python manage.py migrate
    

回答by Tobias Lorenz

This issue might be caused by one of the apps you're using. If you check the traceback carefully, you might already find the delinquent.

此问题可能是由您正在使用的应用程序之一引起的。如果您仔细检查回溯,您可能已经找到了违规者。

I had those issues using django-debug-toolbarand zinnia.

我在使用django-debug-toolbar和 时遇到了这些问题zinnia

If you are using the django-debug-toolbarthis might be a solution:

如果您正在使用django-debug-toolbar这可能是一个解决方案:

Try following the steps for the explicit setup: http://django-debug-toolbar.readthedocs.org/en/1.2.2/installation.html#explicit-setup

尝试按照显式设置的步骤操作:http: //django-debug-toolbar.readthedocs.org/en/1.2.2/installation.html#explicit-setup

Alternatively remove debug_toolbarfrom your INSTALLED APPS.

或者debug_toolbar从您的INSTALLED APPS.

If that doesn't help or if another app is causing the issue, try to temporarily remove all imports (e.g. installed app, urls, custom views, settings), which are displayed in the traceback.

如果这没有帮助,或者如果另一个应用程序导致了问题,请尝试暂时删除回溯中显示的所有导入(例如已安装的应用程序、网址、自定义视图、设置)。

回答by Sandeep Balagopal

A horrible code lead to this error for me. I had a global variable to get the current site

一个可怕的代码对我来说导致了这个错误。我有一个全局变量来获取当前站点

SITE = Site.objects.get(pk=1)

SITE = Site.objects.get(pk=1)

this was evaluated during migration and lead to the error.

这在迁移期间进行了评估并导致错误。

回答by user2723240

I'm late, but I ran into the same issue with django v 1.11.

我迟到了,但我在 django v 1.11 中遇到了同样的问题。

The issue was that I was rebuilding a model outside the normal def() and in a form() [I use the models for a choice] The traceback should have the .py file listed

问题是我正在正常 def() 之外重建模型并以 form() [我使用模型进行选择] 回溯应该列出 .py 文件

e.g.

例如

 File "filepath/views.py", line 67, in <module>
    some_variable = some_model.objects.get(name ='name')

So I had to comment it out to rebuild my migrations

所以我不得不将其注释掉以重建我的迁移

回答by George Sferopoulos

Going to leave this here for future me:

打算把这个留在这里给未来的我:

python manage.py makemigrations allauth

python manage.py makemigrations allauth

This worked for me, I forgot why, took me too long to figure out how I fixed this the first time

这对我有用,我忘记了为什么,花了太长时间才弄清楚我是如何第一次解决这个问题的

Edit: makemigrations sometimes doesnt make 3rd party things like allauth which some of my projects use, so I have to specify those ones

编辑:makemigrations 有时不会像我的一些项目使用的 allauth 这样的 3rd 方东西,所以我必须指定那些

回答by Steckelfisch

I experienced the same problem with creating a new empty database for my project (which uses zinnia)

我在为我的项目(使用 zinnia)创建一个新的空数据库时遇到了同样的问题

Running 'manage migrate site' before 'manage migrate' did not solve anything. It seems that the complete project was loaded before any table creating was done.

在“管理迁移”之前运行“管理迁移站点”并没有解决任何问题。似乎在完成任何表创建之前加载了完整的项目。

I resolved to catching the errors that importing the zinnia releated app produced.

我决定捕捉导入百日草相关应用程序产生的错误。

e.g.: in the urls.py of the app

例如:在应用程序的 urls.py 中

urlpatterns = None
app_name = 'something'

try:
    from .views import MyEntryCreate


    urlpatterns = [

    url(r'^blogentry/create/$',
        login_required(MyEntryCreate.as_view()),
        name='zinnia_entry-add'),

    ]
except Exception as e:
    logger.error(app_name+" Error urls: "+str(e))
    urlpatterns = []

Had to do something like that elsewhere in that app, and 'manage migrate' worked again.

不得不在该应用程序的其他地方做类似的事情,并且“管理迁移”再次起作用。