1

I am working on the model of my rails based website, and created a model class called ItemAttributes, which defines a set of valid attributes for a specific item. For example, 'bed size' is an attribute of the item 'bed.' I have also created a AttributeValue class which defines valid values for Attributes, like 'king' 'queen' 'full' etc.

I am attempting to populate the PostgreSQL database on heroku with a migration, but it throws this rather unhelpful error (the migration works locally on SQLite):

PGError: ERROR:  current transaction is aborted, commands ignored until end of transaction block
:             SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull
              FROM pg_attribute a LEFT JOIN pg_attrdef d
                ON a.attrelid = d.adrelid AND a.attnum = d.adnum
             WHERE a.attrelid = '"attribute_values"'::regclass
               AND a.attnum > 0 AND NOT a.attisdropped
             ORDER BY a.attnum

Here is the migration I am using:

class AddBedSizeValues < ActiveRecord::Migration
  def self.up
    id = ItemAttribute.find_by_name('bed size').id

    AttributeValue.create(
      :name => 'king',
      :item_attribute_id => id
    )
    AttributeValue.create(
      :name => 'queen',
      :item_attribute_id => id
    )
    AttributeValue.create(
      :name => 'full',
      :item_attribute_id => id
    )
    AttributeValue.create(
      :name => 'x-long twin',
      :item_attribute_id => id
    )
    AttributeValue.create(
      :name => 'twin',
      :item_attribute_id => id
    )
  end
2
  • I tried removing all of the "creates" in this migration, and it went through without a hitch. Once I add just one create back into the migration, the same error returns. Commented Apr 12, 2011 at 17:55
  • 1
    The number one cause of grief for Heroku developers is using SQLite locally. PostgreSQL is free. Download it, install it, and stop using SQLite. Commented May 21, 2011 at 11:08

1 Answer 1

1

This error is given when in the same transaction there has been an earlier error. Find and resolve that error. You can use savepoints if you expect certain error and don't want to rollback the complete transaction.

Edit, some clarifications

To clarify, the cases where I have seen the error the flow was about as follows:

BEGIN; -- start of transaction
SOME QUERY; -- Causes error but error is ignored
SECOND QUERY; -- Causes the error you get because it is still in the same transaction

After an error the transaction must be rolledback and a new one started before you can continue, or you must rollback to a savepoint.

It could be you have hit some other condition that gives this error but maybe you should check the logs in PGDATA/pg_log to check if your engine is logging some error rails is ignoring.

If that doesn't help can you try to create a log of all the actual queries (instead of the rails code) executed during the migration.

Sign up to request clarification or add additional context in comments.

3 Comments

I'm not sure what you mean by this. I'm pretty sure there is no error previous to the creation of these attribute values. I've slimmed down my migration to just the first of the creates above, and that still causes the error. If I remove all of the creates, the error disappears.
Clarified my post, hope it helps.
I voted for this answer, because it helped me solve my problem. The unhelpful message was in fact due to an ignored error, followed by another one. To identify the problem, I suggest: 1. look at your log/development.log file which will give you most of the information you need (eg. the SQL requests, and you can even insert some tracing in your migration with a simple puts), and if this is not sufficient, you may want to have a look to your PostgreSQL database logs (I'm using a local PG server however, don't know if you can do this on Heroku).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.