将Rails应用程序推送到Heroku-PG :: UndefinedColumn:错误:关系列不存在

时间:2018-08-15 09:26:17

标签: ruby-on-rails ruby heroku ruby-on-rails-5 heroku-postgres

我正在尝试将Rails应用程序推送到Heroku,但是出现以下错误:“ PG :: UndefinedColumn:错误:关系” stores“的列” toilet_available“不存在”

然后我从stores表中删除了“ toilet_available”列,但是仍然出现错误。

我的模式如下:

ActiveRecord::Schema.define(version: 20180814220216) do

  create_table "stores", force: :cascade do |t|
    t.string "name"
    t.string "address"
    t.float "beer_cost"
    t.text "facilities"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.float "latitude"
    t.float "longitude"
    t.boolean "toilet"
    t.string "address_line2"
    t.string "address_line3"
    t.integer "user_id"
    t.integer "toilet_id"
  end

  create_table "toilets", force: :cascade do |t|
    t.string "toilet_available"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
  end

  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.string "current_sign_in_ip"
    t.string "last_sign_in_ip"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.index ["email"], name: "index_users_on_email", unique: true
    t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
  end

end

运行heroku run rails db:migrate后的输出:

Running rails db:migrate on ⬢ hellospaeti... up, run.5788 (Free)
   (1.4ms)  SELECT pg_try_advisory_lock(3990924734019646395)
   (1.8ms)  SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
Migrating to RemoveToiletAvailableFromStores (20180627115344)
   (1.1ms)  BEGIN
== 20180627115344 RemoveToiletAvailableFromStores: migrating ==================
-- remove_column(:stores, :toilet_available, :string)
   (2.8ms)  ALTER TABLE "stores" DROP "toilet_available"
   (1.2ms)  ROLLBACK
   (1.3ms)  SELECT pg_advisory_unlock(3990924734019646395)
rails aborted!
StandardError: An error has occurred, this and all later migrations canceled:

PG::UndefinedColumn: ERROR:  column "toilet_available" of relation "stores" does not exist
: ALTER TABLE "stores" DROP "toilet_available"

迁移文件:

class RemoveToiletAvailableFromStores < ActiveRecord::Migration[5.1]
  def change
    remove_column :stores, :toilet_available, :string
  end
end

无法弄清为什么它不起作用,有点担心,在尝试了几次不同的迁移后,我将事情弄得更糟。有什么想法吗?

0 个答案:

没有答案