rspec returns “PG::Error: ERROR: relation ”table_name“ does not exist”

后端 未结 4 923
礼貌的吻别
礼貌的吻别 2021-02-05 20:43

Environment is REE(2011.12) on rvm, rspec 2.8.0, rails 3.0.6, and pg 0.13.2. Using PostgreSQL 8.3.17 on CentOS 5.6. The db:migrate have work correctly. But rspec have got follow

4条回答
  •  野的像风
    2021-02-05 21:35

    I've run into this in two instances (updated 6/13/2012):

    First:

    I haven't yet migrated my test database...

    rake db:migrate

    ...which you need to do before both db:test:prepare and db:test:load.

    When you invoke rspec it should prepare and load your database for you anyway. You shouldn't have to do that by hand.

    Second:

    A typo in my migration. I accidentally reversed my table and column names in the parameter list.

    A migration on a Rails 3.1 project:

    def change
      add_column :had_import_errors, :studies, :boolean, :default => false
      add_column :import_data_cache, :studies, :text
    end
    

    ...which is wrong, because has_import_errors and import_data_cache are my column names, and they therefore should come second, not first.

    The correct migration, with the table name first was:

    def change
      add_column :studies, :had_import_errors, :boolean, :default => false
      add_column :studies, :import_data_cache, :text
    end
    

提交回复
热议问题