2

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

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

我从这个问题中了解到,问题可能源于之前的交易未正确执行:

“当查询产生错误并且您尝试运行另一个查询而不首先回滚事务时,这就是 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

视图.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()
4

1 回答 1

2

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

于 2013-04-20T15:10:08.963 回答