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

27👍

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

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

  2. Set DEBUG=1, or SQL won’t be logged

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

  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. 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 configuration:

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:

  1. Read and paste the installation commands in /tmp

  2. Change dir to autocomplete_light_env/src/django-autocomplete-light/test_project

  3. Open test_project/settings.py, replace the LOGGING configuration by the one above

  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=[]
👤jpic

Leave a comment