我正在尝试在Rails中为外键添加索引:
add_index :reports, :unit_id
不幸的是,它给了我以下错误:
== AddIndexToReportsUnitId: migrating ========================================
-- add_index(:reports, :unit_id)
rake aborted!
An error has occurred, this and all later migrations canceled:
PG::Error: ERROR: current transaction is aborted, commands ignored until end of transaction block
:
SELECT distinct i.relname, d.indisunique, d.indkey, pg_get_indexdef(d.indexrelid), t.oid,
m.amname, pg_get_expr(d.indpred, t.oid), pg_get_expr(d.indexprs, t.oid)
FROM pg_class t
INNER JOIN pg_index d ON t.oid = d.indrelid
INNER JOIN pg_class i ON d.indexrelid = i.oid
INNER JOIN pg_am m ON i.relam = m.oid
WHERE i.relkind = 'i'
AND d.indisprimary = 'f'
AND t.relname = 'reports'
AND i.relnamespace IN (SELECT oid FROM pg_namespace WHERE nspname = ANY (current_schemas(false)) )
ORDER BY i.relname
知道为什么会这样吗?它只在我尝试向此特定列添加索引时发生。我能够将索引添加到另一列。
答案 0 :(得分:0)
好的,我想我明白为什么会这样。我已经在该列上有一个索引:
${PATH};C:\cygwin\bin
哇,我希望它在提出异常时给了我更好的暗示。