2

UPDATE: The problem wasn't with the previous transaction, it was happening because the database wasn't synced / migrated properly.

I've recently switched my local database to Postgres, and I'm now getting an InternalError.

I understand from this question that the problem likely originates from a previous transaction not executing properly:

"This is what postgres does when a query produces an error and you try to run another query without first rolling back the transaction."

However, from the logs below, it seems like the first query, DEBUG (0.0001), executes fine (I also tested this exact query though the 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,)

Full SQL Logs

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()
Community
  • 1
  • 1
Brian Dant
  • 4,029
  • 6
  • 33
  • 47

1 Answers1

2

The problem was that my database wasn't migrated properly. Apparently this error can come from (at least) both a) the previous transaction, or b) the database not being synced properly by south.

Brian Dant
  • 4,029
  • 6
  • 33
  • 47