2016-03-23 7 views
0

私のレールアプリケーションの移行に関するいくつかの問題があります。これは、移行ファイルの抜粋である誰かがこのエラーの原因をトラブルシューティングするのに役立つことができます:ActiveRecord :: Migration Error PG :: WrongObjectType 'table'はビューではありません

PG::WrongObjectType: ERROR: "contributions" is not a view 

class ReplaceContributionView < ActiveRecord::Migration 
    def up 
    execute <<-SQL 
     CREATE OR REPLACE VIEW contributions AS (
     (
     SELECT id, 
     id AS person_id, 
     project_id AS project_id, 
     name_fact_id AS name_fact_id, 
     null AS position_id 
     FROM people 
     WHERE project_id IS NOT NULL 

     .........etc etc. ........... 
    end 

    def down 
    ......... 
    end 
end 

contributionsテーブルのための私の開発データベースを確認することがあることを示している私は、保留中のマイグレーションを実行すると、私はこのようなエラーを受け取ります確かに眺め。

\d contributions 

Materialized view "public.contributions" 
Column | Type | Modifiers 
--------------+---------+----------- 
id   | bigint | 
person_id | bigint | 
project_id | integer | 
name_fact_id | integer | 
position_id | integer | 
Indexes: 
    "index_contributions_on_id" UNIQUE, btree (id) 
    "index_contributions_on_project_id" btree (project_id) 

は、私も自分のテスト・データベースに移行することは一切エ​​ラーが発生していないことを指摘したいと私は問題なくmigraterollbackにできています。

私はこの移行に固執しており、解決するまでは何もできません。何が問題なの? viewmaterialized viewが別のものでない限り、それは明らかに見通しです。誰にもアイデアはありますか?ヘルプをいただければ幸いです。

答えて

0

ビューをドロップして、代わりに「VIEWのCREATE OR REPLACE」は、それを作成してみてください:

def up 
    execute('DROP VIEW contributions') 
    execute('CREATE VIEW contributions AS (
    (
    SELECT id, 
     id AS person_id, 
     project_id AS project_id, 
     name_fact_id AS name_fact_id, 
     null AS position_id 
    FROM people 
    WHERE project_id IS NOT NULL 

    .........etc etc. ...........' 
end 

表があることは明らかであるように、また、あなたがテーブル「v_contributions」を命名検討する必要がありますビューテーブル。

関連する問題