PG :: UndefinedColumn:ERROR:关系“users”的列“oauth_expires_in”不存在(在Rails 5中)

时间:2017-07-09 11:31:08

标签: ruby-on-rails ruby postgresql migration ruby-on-rails-5

我收到以下错误尝试删除我刚刚创建的列

  

PG :: UndefinedColumn:ERROR:关系列“oauth_expires_in”   “用户”不存在

这是我的第一个迁移文件。

20170709013540_add_oauth_expires_in_to_users.rb
class AddOauthExpiresInToUsers < ActiveRecord::Migration[5.0]
  def change
    add_column :users, :oauth_expires_in, :integer
  end
end

因此在schema.rb

中的表“users”中创建了这个新列
create_table "users", force: :cascade do |t|
  t.string   "email",                  default: "",    null: false
  t.string   "encrypted_password",     default: "",    null: false
  t.string   "reset_password_token"
  t.datetime "reset_password_sent_at"
  t.datetime "remember_created_at"
  t.integer  "sign_in_count",          default: 0,     null: false
  t.datetime "current_sign_in_at"
  t.datetime "last_sign_in_at"
  t.inet     "current_sign_in_ip"
  t.inet     "last_sign_in_ip"
  t.datetime "created_at",                             null: false
  t.datetime "updated_at",                             null: false
  t.string   "name"
  t.string   "oauth_token"
  t.string   "oauth_secret"
  t.string   "photo"
  t.boolean  "admin",                  default: false, null: false
  t.integer  "oauth_expires_in"
  t.index ["email"], name: "index_users_on_email", unique: true, using: :btree
  t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree
end

然后我创建了一个新的迁移文件来删除我创建的列。见下文:

20170709111539_remove_oauth_expires_in_from_users.rb
class RemoveOauthExpiresInFromUsers < ActiveRecord::Migration[5.0]
  def change
    remove_column :users, :oauth_expires_in, :integer
  end
end

当我运行迁移时,我收到以下错误:

== 20170709111539 RemoveOauthExpiresInFromUsers: migrating ====================
-- remove_column(:users, :oauth_expires_in, :integer)
rails aborted!
StandardError: An error has occurred, this and all later migrations canceled:

PG::UndefinedColumn: ERROR:  column "oauth_expires_in" of relation "users" does not exist
: ALTER TABLE "users" DROP "oauth_expires_in"
/Users/davidverbustel/code/davidverbustel/barky/db/migrate/20170709111539_remove_oauth_exp    ires_in_from_users.rb:3:in `change'
./bin/rails:4:in `require'
./bin/rails:4:in `<main>'
ActiveRecord::StatementInvalid: PG::UndefinedColumn: ERROR:  column "oauth_expires_in" of     relation "users" does not exist
: ALTER TABLE "users" DROP "oauth_expires_in"
/Users/davidverbustel/code/davidverbustel/barky/db/migrate/20170709111539_remove_oauth_exp    ires_in_from_users.rb:3:in `change'
./bin/rails:4:in `require'
./bin/rails:4:in `<main>'
PG::UndefinedColumn: ERROR:  column "oauth_expires_in" of relation "users" does not exist
/Users/davidverbustel/code/davidverbustel/barky/db/migrate/20170709111539_remove_oauth_exp    ires_in_from_users.rb:3:in `change'
./bin/rails:4:in `require'
./bin/rails:4:in `<main>'
Tasks: TOP => db:migrate

我一直在摸不着头脑,但却无法发现错误?!。

任何想法都会非常感激。 谢谢!

0 个答案:

没有答案