更新: 問題は以前のトランザクションではなく、データベースが適切に同期/移行されなかったために発生していました。
最近、ローカル データベースを Postgres に切り替えたところ、InternalError が発生しました。
この質問から、問題は以前のトランザクションが正しく実行されていないことが原因である可能性が高いことがわかりました。
「これは、クエリでエラーが発生し、最初にトランザクションをロールバックせずに別のクエリを実行しようとしたときに postgres が行うことです。」
ただし、以下のログから、最初のクエリ が正常に実行されているように見えますDEBUG (0.0001)
(Django DB シェルを使用して、この正確なクエリもテストしました)。
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()