python - 升级到 Django 1.8.13。测试失败但应用程序有效。 Postgresql 表重复

标签 python django postgresql

经过长时间的拖延,我决定将我的 django 应用程序从 1.7.11 升级到 1.8.13(由于它的 LTS)。一切都很顺利,在修复了一些明显的错误之后(我需要升级到 django-mptt==0.8.4django-filter==0.13.0 以及 Django==1.8.13) 并删除了一些冲突的字段属性,我想正常运行我的服务器。

显然我的应用运行良好(我手动测试网站,执行 2-3 个操作,我没有看到明显的错误)。

但是,在运行测试时(使用 ./manage.py test -v 3),我得到以下输出:

[...]
Running pre-migrate handlers for application debug_toolbar
  Creating tables...
    Creating table corsheaders_corsmodel
    Creating table actstream_follow
    Creating table actstream_action
    Creating table thumbnail_kvstore
    Creating table django_comments
    Creating table django_comment_flags
    Creating table tagging_tag
    Creating table tagging_taggeditem
    Creating table blog_newslettersubscription
    Running deferred SQL...
Traceback (most recent call last):
  File "/home/user/workspace/project/lib/python3.4/site-packages/django/db/backends/utils.py", line 62, in execute
    return self.cursor.execute(sql)
psycopg2.ProgrammingError: relation "app_user" does not exist.

应用 app 是我的 AUTH_USER_MODEL 所在的位置,即在我的 settings.py 中:

AUTH_USER_MODEL = 'app.User'

在我的 app/models.py 中:

class User(AbstractBaseUser):
    [...]

我已经阅读了很多问题,例如 this , this , this , this还有this .我进行了很多搜索,但找不到解决我的问题的方法(没有一个有效)。

奇怪的是,如果我检查数据库(Postgresql),表存在。执行:

SELECT relname, reltuples, relpages * 8 / 1024 AS "MB" FROM pg_class ORDER BY relpages DESC;

返回:

                             relname                    |  reltuples  |  MB   
...                                                     |             |
app_user                                                |        4034 |     0
...                                                     |             |

有什么线索吗?任何帮助将非常感激!提前致谢。

更新: 我的INSTALLED_APPS:

INSTALLED_APPS = (
    'grappelli',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'django.contrib.gis',
    'crispy_forms',
    'rosetta',
    'django_extensions',
    'django_slack',
    'filebrowser',
    'mptt',
    'corsheaders',
    'actstream',
    'compressor',
    'sorl.thumbnail',
    'geoposition',
    'reversion',
    'rest_framework',
    'rest_framework.authtoken',
    'rest_framework_swagger',
    'rest_auth',
    'django_comments',
    'tagging',
    'allauth',
    'allauth.account',
    'allauth.socialaccount',
    'allauth.socialaccount.providers.facebook',
    'rest_auth.registration',
    'import_export',
    'oauth2_provider',
    'places',
    'tasks',
    'transmeta',
    'app',
)

最佳答案

让我们再看看你的错误,尤其是这一点:

   Creating table blog_newslettersubscription
    Running deferred SQL...
Traceback (most recent call last):
  File "/home/user/workspace/project/lib/python3.4/site-packages/django/db/backends/utils.py", line 62, in execute
    return self.cursor.execute(sql)
psycopg2.ProgrammingError: relation "app_user" does not exist.

这就是说,您的blog 应用程序引用您的app 中的表,因此app 应该在您的blog 之前设置.py

按如下方式修改您的 INSTALLED_APPS

INSTALLED_APPS = (
   'grappelli',
   ...
   'transmeta',
   'app','blog')

关于python - 升级到 Django 1.8.13。测试失败但应用程序有效。 Postgresql 表重复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37990496/

相关文章:

python - Django Heroku Postgres - 编程错误 : relation does not exist

java - 具有偏移和限制的 0..n 结果转换会产生不准确的结果

python - 使用 C 对象指针构建 PyObject*

django - Python 字典在 django 模板中无法访问

python - 如何在主方法中引发自定义异常?

django - 如何扩展聊天应用程序数据库?

python - 将搜索结果链接到其自己的详细信息页面

postgresql - 如何为 postgres 日志文件夹设置卷 - 权限被拒绝错误

python - 如何在 Python 中进行按位非运算?

python - 在 pyspark 中合并重叠的日期范围