简体   繁体   English

如何调试:内部错误当前事务被中止,命令被忽略直到事务块结束

[英]How to debug: Internal Error current transaction is aborted, commands ignored until end of transaction block

Hi Stackoverflow people, 嗨Stackoverflow人,

I do my first steps with GeoDjango and I am looking for better options to check faulty sql statements. 我用GeoDjango做了我的第一步,我正在寻找更好的选项来检查错误的sql语句。

So far, I simply wanted to safe a lng+lat point in my postgresql table. 到目前为止,我只是想在postgresql表中保护lng + lat点。

The model is defined with: 该模型定义为:

    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: 但是当我尝试保存表单时收到以下错误:

Exception Type: InternalError Exception Value: current transaction is aborted, commands ignored until end of transaction block 异常类型:InternalError异常值:当前事务被中止,命令被忽略,直到事务块结束

What is the reason for this error? 这个错误的原因是什么? I believe that there could be something wrong with the sql statement, but what is the best way to check? 我相信sql语句可能有问题,但检查的最佳方法是什么? Django just provides with general error message "Internal Error". Django只提供一般错误消息“内部错误”。

Thank you for your help and suggestions! 感谢您的帮助和建议!

In most cases this means that the previous SQL statement failed to execute. 在大多数情况下,这意味着先前的 SQL语句无法执行。 In this case you should: 在这种情况下,你应该:

  1. Enable SQL logging , see the following snippet to paste in settings.py 启用S​​QL 日志记录 ,请参阅以下代码段以粘贴settings.py

  2. Set DEBUG=1 , or SQL won't be logged 设置DEBUG = 1 ,否则将不记录SQL

  3. Run runserver again , and you should see all SQL queries in the console 再次运行runserver ,您应该在控制台中看到所有SQL查询

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

SQL Logging configuration: 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',
       },  
   }   
}

If this configuration does not provide any additional console output with runserver , then feel free to try django-autocomplete-light's example test_project : 如果此配置没有为runserver提供任何其他控制台输出,那么请随意尝试django-autocomplete-light的示例test_project

  1. Read and paste the installation commands in /tmp /tmp读取并粘贴安装命令

  2. Change dir to autocomplete_light_env/src/django-autocomplete-light/test_project 将目录更改为autocomplete_light_env/src/django-autocomplete-light/test_project

  3. Open test_project/settings.py , replace the LOGGING configuration by the one above 打开test_project/settings.py ,用上面的那个替换LOGGING配置

  4. 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=[]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 InternalError:当前事务中止,命令被忽略,直到事务块结束 - InternalError: current transaction is aborted, commands ignored until end of transaction block DatabaseError:当前事务被中止,在事务块结束之前忽略命令? - DatabaseError: current transaction is aborted, commands ignored until end of transaction block? django-当前事务中止,命令被忽略,直到事务块结束 - django - current transaction is aborted, commands ignored until end of transaction block 错误:当前事务中止,创建新记录时命令被忽略,直到事务块结束 - Error: current transaction is aborted, commands ignored until end of transaction block while creating a new record DatabaseError:当前事务中止,命令被忽略,直到事务块结束-在隐身模式下,但正常情况下没有错误 - DatabaseError: current transaction is aborted, commands ignored until end of transaction block - in incognite mode but no error in normal 使用 Python 连接到 Redshift 数据 - 错误:当前事务被中止,命令被忽略,直到事务块结束 - Connecting to Redshift Data Using Python - Error: current transaction is aborted, commands ignored until end of transaction block django reg extension-当前事务中止,命令被忽略,直到事务块结束 - django reg extend - current transaction is aborted, commands ignored until end of transaction block psycopg2.errors.InFailedSqlTransaction:当前事务被中止,命令被忽略直到事务块结束 - psycopg2.errors.InFailedSqlTransaction: current transaction is aborted, commands ignored until end of transaction block SQLAlchemy + postgres:(InternalError)当前事务中止,命令被忽略,直到事务块结束 - SQLAlchemy + postgres : (InternalError) current transaction is aborted, commands ignored until end of transaction block Django:通过添加m2m导致“当前事务中止,命令被忽略,直到事务块结束” - Django: Added m2m via through causes 'current transaction is aborted, commands ignored until end of transaction block'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM