PG::DependentObjectsStillExist: ERROR: cannot drop column xxx_id of xxxxx because other objects depend on it

PG::DependentObjectsStillExist: ERROR: cannot drop column xxx_id of xxxxx because other objects depend on it

我正在尝试从名为 subscriptions 的 table 中删除 foreign_key user_id

模特协会如

#user.rb

has_many :subscriptions
has_many :orders_through_vehicle, through: :subscriptions, source: :line_items
accepts_nested_attributes_for :subscriptions

  #subscription.rb

  # Indexes
  #
  #  idx_user_id (user_id)

  belongs_to :user, required: true

当我运行迁移时, remove_column :subscriptions, :user_id,它抛出以下错误:

PG::DependentObjectsStillExist: ERROR:  cannot drop column user_id of table subscriptions because other objects depend on it
DETAIL:  view vw_customer_size depends on column user_id of table subscriptions
view vw_subscriptions_daily_report depends on column user_id of table subscriptions
HINT:  Use DROP ... CASCADE to drop the dependent objects too.

我不关心这些 Postgres 视图。我是否也必须删除它们,如何使用 rails 迁移来完成?

谢谢

我可以解决这个问题。这里需要先把两个数据库视图去掉,

    execute <<-SQL
      drop view if exists vw_customer_size
    SQL

    execute <<-SQL
      drop view if exists vw_subscriptions_daily_report
    SQL

    remove_column :subscriptions, :user_id