开发者

Heroku PostgreSQL Migration Issue

开发者 https://www.devze.com 2023-02-24 07:26 出处:网络
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 attri

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 ab开发者_运维问答orted, 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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消