我正在将我自己的存储库克隆到我的本地机器上,另一位开发人员已经完成了一些工作。我正在尝试迁移数据库并收到此错误:
/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)
架构.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
任何建议都很好
最佳答案
很确定您的 answers
表中没有 slug
列。
因此使用迁移添加:
rails g migration AddSlugToAnswers slug:string
然后,运行迁移:
bundle exec rake db:migrate
关于ruby-on-rails - rake 数据库 :migrate error 'PG::UndefinedColumn: ERROR: column "slug"does not exist',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32296178/