如何在Django DB连接中打开PostgreSQL VERBOSITY? [英] How to turn on PostgreSQL VERBOSITY in django db connection?

查看:53
本文介绍了如何在Django DB连接中打开PostgreSQL VERBOSITY?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是对此的后续问题:

Postgres:更详细的错误消息:我缺少表名

PostgreSQL 9.6在9.6版中改进了错误消息.

PostgreSQL 9.6 improved error messages with version 9.6.

使用 psql ,您可以将其启用 \ set VERBOSITY verbose .

With psql you can enable it \set VERBOSITY verbose.

如何为django ORM内部的每个连接启用此功能?

How to enable this for every connection inside django ORM?

背景:我想要更好的错误消息.

Background: I want better error messages.

示例:我在这样的消息中缺少表名

Example: I am missing the table name in messages like this

IntegrityError: null value in column "date" violates not-null constraint
DETAIL:  Failing row contains (10005, null, f, TEST, MAIL).

我认为 9.6版本的相关部分笔记是这样的:

在libpq中添加支持以重新生成具有不同详细级别(Alex Shulgin)的错误消息

Add support in libpq for regenerating an error message with a different verbosity level (Alex Shulgin)

这是通过新函数PQresultVerboseErrorMessage()完成的.这支持psql的新\ errverbose功能,对其他客户端也可能有用.

This is done with the new function PQresultVerboseErrorMessage(). This supports psql's new \errverbose feature, and may be useful for other clients as well.

我使用psycopg2作为数据库适配器.

I use psycopg2 as database adapter.

推荐答案

尝试一下

# settings.py
DATABASES = {
    'default': {
        'ENGINE': '...',
        'OPTIONS': {
            'init_command': "SET log_error_verbosity TO 'verbose'",
        },
    }
}

测试查询

SELECT setting FROM pg_settings WHERE name = 'log_error_verbosity'

这篇关于如何在Django DB连接中打开PostgreSQL VERBOSITY?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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