【发布时间】:2023-03-08 14:24:01
【问题描述】:
提供一些背景知识。我是 Ruby on Rails 的新手,我正在创建一个评论网站,用户可以在其中报告评论。我玩弄了一个“可报告的”多态关联,然后报告表格。后来我删除了“报告”表并创建了另一个报告表。早期迁移不允许创建新的报告表迁移,因此我在迁移早期迁移的名称旁边添加了“1”。
20180311071357_create_reports_1.rb
class CreateReports1 < ActiveRecord::Migration[5.0]
def change
create_table :reports do |t|
t.string :reason
t.text :description
t.string :email
t.belongs_to :reportable, polymorphic: true
t.timestamps
end
end
end
快进到现在。我有一段时间没有对 Heroku 进行生产提交,我只是在构建应用程序。当我推送到 heroku 时,出现以下错误-
heroku run rake db:migrate --trace
Running rake db:migrate --trace on ⬢ housereview... up, run.6689 (Free)
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:migrate
(4.0ms) SELECT pg_try_advisory_lock(2386658352535867725);
ActiveRecord::SchemaMigration Load (4.6ms) SELECT "schema_migrations".* FROM "schema_migrations"
Migrating to DeleteReports1 (20180318091834)
(1.2ms) BEGIN
== 20180318091834 DeleteReports1: migrating ===================================
-- drop_table(:reports)
(2.8ms) DROP TABLE "reports"
(2.6ms) ROLLBACK
(2.3ms) SELECT pg_advisory_unlock(2386658352535867725)
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
PG::DependentObjectsStillExist: ERROR: cannot drop table reports because other objects depend on it
DETAIL: constraint fk_rails_cfc8432c20 on table notes depends on table reports
HINT: Use DROP ... CASCADE to drop the dependent objects too.
: DROP TABLE "reports"
...
/app/bin/bundle:3:in `load'
/app/bin/bundle:3:in `<main>'
Caused by:
ActiveRecord::StatementInvalid: PG::DependentObjectsStillExist: ERROR: cannot drop table reports because other objects depend on it
DETAIL: constraint fk_rails_cfc8432c20 on table notes depends on table reports
HINT: Use DROP ... CASCADE to drop the dependent objects too.
: DROP TABLE "reports"
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.6/lib/active_record/connection_adapters/postgresql/database_statements.rb:98:in `async_exec'
.......
/app/bin/bundle:3:in `load'
/app/bin/bundle:3:in `<main>'
Caused by:
PG::DependentObjectsStillExist: ERROR: cannot drop table reports because other objects depend on it
DETAIL: constraint fk_rails_cfc8432c20 on table notes depends on table reports
HINT: Use DROP ... CASCADE to drop the dependent objects too.
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.6/lib/active_record/connection_adapters/postgresql/database_statements.rb:98:in `async_exec'
这是我的架构-
ActiveRecord::Schema.define(version: 20180407122611) do
create_table "locations", force: :cascade do |t|
t.string "address"
t.string "street_number"
t.string "locality"
t.string "postal_code"
t.string "country"
t.string "route"
t.string "state"
end
create_table "notes", force: :cascade do |t|
t.text "description"
t.integer "report_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["report_id"], name: "index_notes_on_report_id"
end
create_table "reports", force: :cascade do |t|
t.string "reason"
t.text "description"
t.integer "user_id"
t.integer "review_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "completed_at"
t.index ["review_id"], name: "index_reports_on_review_id"
end
create_table "reviews", force: :cascade do |t|
t.string "title"
t.string "duration"
t.text "positive"
t.text "negative"
t.integer "location_id"
t.integer "user_id"
t.integer "rating_safety"
t.integer "rating_neighbour"
t.integer "rating_owner"
t.integer "rating_school"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "rating_overall"
t.boolean "blocked"
t.index ["location_id"], name: "index_reviews_on_location_id"
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.string "confirmation_token"
t.datetime "confirmed_at"
t.datetime "confirmation_sent_at"
t.string "unconfirmed_email"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "admin", default: false
t.string "first_name"
t.string "last_name"
t.string "locality"
t.string "state"
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
我尝试了(几乎)一切来解决这个问题。到目前为止我尝试过的以下事情- - 删除生产应用程序,然后恢复 pgbackup - 删除生产应用程序,然后尝试执行新的“git push heroku master”,然后执行“heroku run rake db:migrate” - 尝试了 drop table 命令,然后再次推送代码并 rake db:migrate - 在 pgsql 中尝试了“DROP TABLE if exists reports cascade;”
以上都没有运气。 该应用程序在 dev (SQLite) 中运行良好,但 heroku 不允许我 rake db:migrate。
提前致谢!
【问题讨论】:
标签: ruby-on-rails postgresql heroku drop-table