Django数据库错误:当social_auth未安装时,缺少表social_auth_usersocialauth [英] Django database error: missing table social_auth_usersocialauth when social_auth is not installed

查看:235
本文介绍了Django数据库错误:当social_auth未安装时,缺少表social_auth_usersocialauth的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Django应用程序中处理一个非常令人费解的错误。当DEBUG = False时,尝试删除用户(通过 user.delete())会给出此数据库错误:

  DatabaseError:relationsocial_auth_usersocialauth不存在
LINE 1:...,social_auth_usersocialauth。extra_dataFROMsocial_au ...

但是,在INSTALLED_APPS中,我没有类似的社交名称或任何东西,在我的数据库中也没有这样的表,我的任何代码都引用了任何类型的东西(我在整个项目文件夹中的社交文件上运行了一个文本搜索) - 而且,当DEBUG = True时,它的工作正常。 social_auth安装在我的系统和我的PYTHONPATH上,但是我看不到这个应用程序在其数据库中应该具有social_auth的表格,更不用说为什么只有在DEBUG = False时才会这样做。



我的应用程序可以通过哪些途径获取这个表,我怎么能说服它呢,不应该在那里?

解决方案

问题可能是由通用关系 /rel =nofollow> Django内容类型。 Django中的关系不仅是静态的,而是由模型和 INSTALLED_APPS 实现,而且还可以通过表 django_content_type 一个数字ID到app_label +模型。可能的动态关系的一个例子是许可或评论。您可以拥有或没有任何已安装应用程序的任何表的权限。您可以为所有内容(例如文章)向用户发表评论,而不改变任何模型。这种关系是通过保存与该模型(表)相关的ContentType的数字ID和相关对象(行)的主键来实现的。



Django不会指望有人可以手动操作数据库。如果您使用 south 进行操作,那么如果卸载应用程序后,请运行 syncdb ,如果您想要自动删除兽类内容类型,则会向南方询问。然后可以将未使用的表安全地删除,而不用后面引用。



(可能的hack:从django_content_type删除其中app_label ='social_auth' south 是不可见的。)



问题的许多部分仍然是开放的。

修改

为什么不是正确的方式:所有的通用关系都是从后代到父级和关于关系的所有数据被保存在后代。如果从INSTALLED_APPS删除子应用程序,那么django.db代码永远不会尝试删除后代,因为它无法识别哪些列包含关系数据。


I'm trying to deal with a very puzzling error in a Django app. When DEBUG=False, trying to delete a user (via user.delete()) gives this database error:

DatabaseError: relation "social_auth_usersocialauth" does not exist
LINE 1: ...", "social_auth_usersocialauth"."extra_data" FROM "social_au...

However, I do not have social_auth or anything by a similar name in INSTALLED_APPS, nor are there any such tables in my database, nor does any of my code reference anything of the sort (I ran a text search on 'social' in the entire project folder) - and again, this works fine when DEBUG=True. social_auth is installed on my system and on my PYTHONPATH, but I cannot see where this app is getting the idea it should be having social_auth's tables in its database, let alone why it only thinks so when DEBUG=False.

What possible pathways could my app be getting this table from and how could I convince it it's not supposed to be there?

解决方案

The problem could be caused by saved generic relations realized by Django content types. Relations in Django are not only static, implemented by models and INSTALLED_APPS but also dynamic implemented by table django_content_type that saves mapping from a numeric id to app_label + model. An example of possible dynamic relationship is a permission or a comment. You can have or have not a permission to any table of any installed application. You can write a comment to everything e.g to an article, to a user to a comment itself without changing any model. This relation is realized by saving numeric id of ContentType related to that model (table) and a primary key of related object (row).

Django does not expect that someone can manipulate the database manually. If you use south for manipulation then if you after uninstalling an application then run syncdb, you are asked by south if you want automatically remove orphant content types. Then can be unused tables removed securely without beeing later referenced.

(Possible hack: delete from django_content_type where app_label='social_auth' but south is unfallible.)

Many parts of the question are still open.

Edit:
Why it was not the right way: All generic relations are from descendants to the parent and all data about the relation are saved in descendant. If the child app is removed from INSTALLED_APPS then django.db code can nevermore try to remove descendants because it can not recognize which columns contain the relation data.

这篇关于Django数据库错误:当social_auth未安装时,缺少表social_auth_usersocialauth的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆