如何调试:内部错误当前事务中止,命令被忽略,直到事务块结束为止 [英] How to debug: Internal Error current transaction is aborted, commands ignored until end of transaction block

查看:2163
本文介绍了如何调试:内部错误当前事务中止,命令被忽略,直到事务块结束为止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi Stackoverflow people,

Hi Stackoverflow people,

我与GeoDjango进行了第一步,我正在寻找更好的选项来检查错误的sql语句。

I do my first steps with GeoDjango and I am looking for better options to check faulty sql statements.

到目前为止,我只是希望在postgresql表中安全的lng + lat点。

So far, I simply wanted to safe a lng+lat point in my postgresql table.

模型定义为:

    geolocation = models.PointField(_('Geo Location'), 
                geography=True, 
                null = True, 
                blank = True,
                help_text=_('Geolocation with Longitude and Latitude'))

    objects = models.GeoManager()

在我看来,我尝试执行以下命令

In my view, I try to execute the following command

savedProject.geolocation = GEOSGeometry('POINT(%s %s)' %(u_lng,u_lat))

但是当我尝试保存表单时,我收到以下错误:

but I receive the following error when I try to save the form:


异常类型:InternalError
异常价值:动作是
中止,命令忽略,直到事务块结束

Exception Type: InternalError Exception Value: current transaction is aborted, commands ignored until end of transaction block

此错误的原因是什么?我相信sql语句可能有问题,但最好的方法是什么? Django只提供一般错误消息内部错误。

感谢您的帮助和建议!

推荐答案

在大多数情况下,这意味着以前的 SQL语句无法执行。在这种情况下,您应该:

In most cases this means that the previous SQL statement failed to execute. In this case you should:


  1. 启用SQL logging ,请参阅以下片段粘贴到settings.py

  1. Enable SQL logging, see the following snippet to paste in settings.py

设置DEBUG = 1 ,否则不会记录SQL

Set DEBUG=1, or SQL won't be logged

再次运行runserver 您应该在控制台中查看所有SQL查询

Run runserver again, and you should see all SQL queries in the console

直接在数据库中执行最后一个SQL查询,然后您应该查找哪些查询失败,然后您应该能够调试它们 - 或打开一个特定于查询导致问题的新问题。您可以使用phpMyAdmin,或直接使用CLI客户端,或任何数据库客户端,逐个执行SQL查询,直到找到需要一些爱的。

Execute the last SQL queries directly in your database, you should then find which queries fail and then you should be able to debug them - or open a new question which is specific to the query that causes the problem. You can use phpMyAdmin, or directly a CLI client, or whatever database client, to execute the SQL queries one by one until you find the one that needs some love.

SQL日志配置:

LOGGING = { 
   'version': 1,
   'disable_existing_loggers': True,
   'formatters': {
       'simple': {
           'format': '%(levelname)s %(message)s',
       },  
   },  
   'handlers': {
       'console':{
           'level':'DEBUG',
           'class':'logging.StreamHandler',
           'formatter': 'simple'
       },  
   },  
   'loggers': {
       'django': {
           'handlers': ['console'],
           'level': 'DEBUG',
       },  
   }   
}

如果此配置不提供任何额外的控制台输出 runserver ,然后随时尝试 django- autocomplete-light的示例test_project

If this configuration does not provide any additional console output with runserver, then feel free to try django-autocomplete-light's example test_project:


  1. 将安装命令读取并粘贴到 / tmp

将目录更改为 autocomplete_light_env / src / django-autocomplete-light / test_project

打开 test_project / settings.py ,将 LOGGING 由上述配置

运行服务器并打开浏览器

Runserver and open your browser

您的控制台将如下所示:

Your console will look like:

Validating models...

0 errors found
Django version 1.4.1, using settings 'test_project.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
DEBUG (0.001) SELECT "django_content_type"."id", "django_content_type"."name", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE ("django_content_type"."model" = taggable  AND "django_content_type"."app_label" = charfield_autocomplete ); args=('taggable', 'charfield_autocomplete')
DEBUG (0.000) 
        SELECT DISTINCT "tagging_tag".id, "tagging_tag".name
        FROM
            "tagging_tag"
            INNER JOIN "tagging_taggeditem"
                ON "tagging_tag".id = "tagging_taggeditem".tag_id
            INNER JOIN "charfield_autocomplete_taggable"
                ON "tagging_taggeditem".object_id = "charfield_autocomplete_taggable"."id"

        WHERE "tagging_taggeditem".content_type_id = 11

        GROUP BY "tagging_tag".id, "tagging_tag".name

        ORDER BY "tagging_tag".name ASC; args=[]

这篇关于如何调试:内部错误当前事务中止,命令被忽略,直到事务块结束为止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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