我接下来的调试步骤是啥? InternalError:当前事务被中止,命令被忽略直到事务块结束

Posted

技术标签:

【中文标题】我接下来的调试步骤是啥? InternalError:当前事务被中止,命令被忽略直到事务块结束【英文标题】:What are my next debugging steps? InternalError: current transaction is aborted, commands ignored until end of transaction block我接下来的调试步骤是什么? InternalError:当前事务被中止,命令被忽略直到事务块结束 【发布时间】:2013-04-13 20:20:35 【问题描述】:

更新:问题不在于之前的事务,而是因为数据库未正确同步/迁移而发生。

我最近将我的本地数据库切换到 Postgres,现在我收到了一个 InternalError。

我从this question 了解到,问题可能源于之前的事务未正确执行:

“当查询产生错误并且您尝试运行另一个查询而不首先回滚事务时,这就是 postgres 所做的。”

但是,从下面的日志来看,第一个查询 DEBUG (0.0001) 似乎执行得很好(我还通过 Django DB Shell 测试了这个确切的查询):

DEBUG (0.001) SELECT "django_site"."id", "django_site"."domain", "django_site"."name" 
FROM "django_site" WHERE "django_site"."id" = 12 ; args=(12,)

完整的 SQL 日志

DEBUG (0.001) SELECT "django_site"."id", "django_site"."domain", "django_site"."name" FROM "django_site" WHERE "django_site"."id" = 12 ; args=(12,)
DEBUG (0.003) INSERT INTO "application_app" ("applied_date", "fname", "lname", 
    "email_address", "phone_number", "skype_id", "applied_track", "college1",       
    "field_of_study1", "graduation_month1", "graduation_year1", "degree1",
    "degree_other1", "working_during_program", "explain_working_during_program", 
    "sib_goal", "twitter_link", "linkedin_link", "other_social_link1",
    "other_social_link2", "other_social_link3", "applied_class", "applied_location",
    "referral", "colossal_failure", "next_week_year_10year", "you_created",
    "your_inspiration", "dev_years_of_exp", "dev_fav_lang", "dev_fav_lang_why",
    "dev_link_youve_built", "dev_link_github", "dev_fav_resource", "prod_cool_prod",     
    "prod_fav_designer", "prod_portfolio", "prod_bad_design", "prod_link_dribble", 
    "mark_ind_trend", "mark_email_to_coworkers", "mark_keep_em_happy",
    "mark_article_or_blog", "sales_why_you", "sales_convince_restaurant",
    "sales_hardest_door", "sales_sale_within_the_year", "housing_needed",
    "program_payment", "any_last_requests") VALUES ('2013-04-20 13:22:06.565691+00:00',
    'Brian', 'Dant', 'test@gmail.com', '', '', 'MAR', '', '', 1, NULL, '', '', false,   
    '', 'GN', '', 'http://linkedin.com/', '', '', '', 'NYCSUM13', '', 'test', 'test',
    'test', 'test', 'test', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 
    '', '', '', '', false, 'UF', 'test') RETURNING "application_app"."id"; args=(u'2013-04-20 13:22:06.565691+00:00',
    u'Brian', u'Dant', u'test@gmail.com', u'', u'', u'MAR', u'', u'', 1, None, '', u'', 
    False, u'', u'GN', u'', u'http://linkedin.com/', u'', u'', '', u'NYCSUM13', '', 
    u'test', u'test', u'test', u'test', u'test', '', '', u'', u'', u'', u'', u'', '', 
    u'', u'', u'', u'', u'', u'', u'', u'', u'', u'', u'', False, u'UF', u'test')
ERROR Internal Server Error: /
Traceback (most recent call last):
  File "/Users/chaz/dev/envs/startupinstitute.com/lib/python2.7/site-packages/django/core/handlers/base.py", line 111, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File "/Users/chaz/dev/projects/startupinstitute.com/apps/application/views.py", line 22, in application
    new_app = f.save()
  File "/Users/chaz/dev/envs/startupinstitute.com/lib/python2.7/site-packages/django/forms/models.py", line 364, in save
    fail_message, commit, construct=False)
  File "/Users/chaz/dev/envs/startupinstitute.com/lib/python2.7/site-packages/django/forms/models.py", line 86, in save_instance
    instance.save()
  File "/Users/chaz/dev/envs/startupinstitute.com/lib/python2.7/site-packages/django/db/models/base.py", line 463, in save
    self.save_base(using=using, force_insert=force_insert, force_update=force_update)
  File "/Users/chaz/dev/envs/startupinstitute.com/lib/python2.7/site-packages/django/db/models/base.py", line 551, in save_base
    result = manager._insert([self], fields=fields, return_id=update_pk, using=using, raw=raw)
  File "/Users/chaz/dev/envs/startupinstitute.com/lib/python2.7/site-packages/django/db/models/manager.py", line 203, in _insert
    return insert_query(self.model, objs, fields, **kwargs)
  File "/Users/chaz/dev/envs/startupinstitute.com/lib/python2.7/site-packages/django/db/models/query.py", line 1593, in insert_query
    return query.get_compiler(using=using).execute_sql(return_id)
  File "/Users/chaz/dev/envs/startupinstitute.com/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 912, in execute_sql
    cursor.execute(sql, params)
  File "/Users/chaz/dev/envs/startupinstitute.com/lib/python2.7/site-packages/debug_toolbar/utils/tracking/db.py", line 153, in execute
    'iso_level': conn.isolation_level,
InternalError: current transaction is aborted, commands ignored until end of transaction block

[20/Apr/2013 08:22:06] "POST / HTTP/1.1" 500 413131
DEBUG (0.002) SELECT "django_site"."id", "django_site"."domain", "django_site"."name" FROM "django_site" WHERE "django_site"."id" = 12 ; args=(12,)
WARNING Not Found: /favicon.ico

views.py:

def application(request):
    if request.method == 'POST':
        f = forms.AppForm(request.POST)
        selected_track = request.POST['applied_track']
        if f.is_valid():
            new_app = f.save() 
            new_app.save()

【问题讨论】:

你真的有一个 id 为 12 的网站吗? 【参考方案1】:

问题是我的数据库没有正确迁移。显然,这个错误可能来自(至少)a)上一个事务,或者 b)南没有正确同步数据库。

【讨论】:

以上是关于我接下来的调试步骤是啥? InternalError:当前事务被中止,命令被忽略直到事务块结束的主要内容,如果未能解决你的问题,请参考以下文章

在linux里,c程序的编辑、编译、调试的详细步骤是啥?

Visual Studio实时调试器 是啥东西?

windbg 怎么调试dmp文件

OPPO realme 2在哪里打开Usb调试模式的简单步骤

无法在 Safari 中检查我的调试版本

你最好的调试提示是啥?