Rake db:migrate error' PG :: UndefinedColumn:ERROR:column" slug"不存在'

时间:2015-08-30 11:43:06

标签: ruby-on-rails ruby postgresql rake

我正在将我自己的repo克隆到我的本地机器上,而另一位开发人员已经完成了一些工作。我正在尝试迁移数据库并收到此错误:

/Users/lewisfrost/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.0.1/lib/active_support/values/time_zone.rb:282: warning: circular argument reference - now
DEPRECATION WARNING: Support for Rails < 4.1.0 will be dropped. (called from <top (required)> at /Users/lewisfrost/frostfires/config/application.rb:8)
==  AddUploadFileToAnswer: migrating ==========================================
-- add_column(:answers, :upload_file, :string)
   -> 0.0006s
-- add_index(:answers, :slug)
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

PG::UndefinedColumn: ERROR:  column "slug" does not exist
: CREATE  INDEX  "index_answers_on_slug" ON "answers"  ("slug")/Users/lewisfrost/frostfires/db/migrate/20140126204815_add_upload_file_to_answer.rb:4:in `change'
ActiveRecord::StatementInvalid: PG::UndefinedColumn: ERROR:  column "slug" does not exist
: CREATE  INDEX  "index_answers_on_slug" ON "answers"  ("slug")
/Users/lewisfrost/frostfires/db/migrate/20140126204815_add_upload_file_to_answer.rb:4:in `change'
PG::UndefinedColumn: ERROR:  column "slug" does not exist
/Users/lewisfrost/frostfires/db/migrate/20140126204815_add_upload_file_to_answer.rb:4:in `change'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)

SCHEMA.rb

  create_table "answers", force: true do |t|
    t.string   "user"
    t.text     "body"
    t.integer  "question_id"
    t.datetime "created_at"
    t.datetime "updated_at"
    t.integer  "user_id"
    t.string   "upload_file"
    t.string   "slug"
  end

迁移文件

class AddUploadFileToAnswer < ActiveRecord::Migration
  def change
    add_column :answers, :upload_file, :string
    add_index :answers, :slug

  end
end

任何建议都很棒

2 个答案:

答案 0 :(得分:1)

非常确定您的slug表格中没有answers列。

所以使用迁移添加:

rails g migration AddSlugToAnswers slug:string

然后,运行迁移:

bundle exec rake db:migrate

答案 1 :(得分:0)

这意味着你的表中没有slug列,但你想索引thia列。

检查列存在的迁移文件,如果没有,则创建迁移以添加slug列,然后运行索引。