Heroku PostgreSQL 迁移问题
我正在研究基于 Rails 的网站的模型,并创建了一个名为 ItemAttributes 的模型类,它为特定项目定义了一组有效属性。例如,“床尺寸”是项目“床”的属性。我还创建了一个 AttributeValue 类,它定义了属性的有效值,例如“king”“queen”“full”等。
我试图通过迁移填充heroku上的PostgreSQL数据库,但它抛出了这个相当无用的错误(迁移在 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
这是我正在使用的迁移:
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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当同一事务中存在较早的错误时,就会出现此错误。找到并解决该错误。如果您预计会出现某些错误并且不想回滚整个事务,则可以使用保存点。
编辑,一些说明
为了澄清,我看到错误的情况流程如下:
发生错误后,事务必须回滚并开始新的事务,然后才能继续,否则您必须回滚到保存点。
可能是您遇到了导致此错误的其他条件,但也许您应该检查 PGDATA/pg_log 中的日志,以检查您的引擎是否记录了某些被忽略的错误。
如果这没有帮助,您可以尝试创建迁移期间执行的所有实际查询(而不是 Rails 代码)的日志。
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:
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.