Rails + Postgres db:migrate 因丢失数据而不是生成数据而失败

Rails + Postgres db:migrate failing on missing data rather than generating it

我正在尝试为现有的 rails 项目设置开发环境,但 运行 一直在解决有关迁移数据库的问题。

这是 config/database.yml

default: &default
  adapter: postgresql
  encoding: utf8
  pool: 5
  timeout: 5000

development:
  <<: *default
  timeout: 5000
  username: postgres
  password:
  database: myapp_development

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  <<: *default
  database: myapp_test

production:
  <<: *default
  database: myapp_production

我已经安装了 'pg' gem (v0.18.3),启动了 postgres 并创建了正确的角色。这是来自 Postgres shell:

\list 的输出
postgres=# \list
                                       List of databases
         Name         |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
----------------------+----------+----------+-------------+-------------+-----------------------
 myapp_development    | raul     | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 myapp_test           | raul     | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 postgres             | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 template0            | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
                      |          |          |             |             | postgres=CTc/postgres
 template1            | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
                      |          |          |             |             | postgres=CTc/postgres
(7 rows)

我收到这个错误:

$ rake db:migrate
rake aborted!
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR:  relation "pools" does not exist
LINE 5:                WHERE a.attrelid = '"pools"'::regclass
                                          ^
:               SELECT a.attname, format_type(a.atttypid, a.atttypmod),
                     pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
                FROM pg_attribute a LEFT JOIN pg_attrdef d
                  ON a.attrelid = d.adrelid AND a.attnum = d.adnum
               WHERE a.attrelid = '"pools"'::regclass
                 AND a.attnum > 0 AND NOT a.attisdropped
               ORDER BY a.attnum

伙计们,找到了!这实际上是我 Gemfile.

中的一条错误线路

具体来说gem 'factory_girl', :require => false

如果您知道耙子损坏的原因,请发表评论。