PGError:错误:关系不存在(rails 3.1.3)

时间:2012-01-13 10:03:55

标签: ruby-on-rails ruby-on-rails-3.1

迁移不会创建表。

迁移效果很好,没有错误。

$rake db:migrate
==  CreateEvents: migrating ===================================================
-- create_table(:events)
NOTICE:  CREATE TABLE will create implicit sequence "events_id_seq" for serial column "events.id"
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "events_pkey" for table "events"
    -> 0.0120s
==  CreateEvents: migrated (0.0125s) ==========================================

但在那之后,出现了错误:

PGError: ERROR:  relation "events" does not exist
LINE 4:              WHERE a.attrelid = '"events"'::regclass
                                    ^
:             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 = '"events"'::regclass
           AND a.attnum > 0 AND NOT a.attisdropped
         ORDER BY a.attnum

如果要查看数据库,则没有表“事件”。 它出现在生产模式中。

1 个答案:

答案 0 :(得分:4)

检查您是否在生产数据库上执行迁移。默认情况下,rake db:migrate使用开发DB。

   rake db:migrate RAILS_ENV="production"