3

我有带有 postgresql 的多租户应用程序轨道,我想删除架构(架构名称 = 子域)并删除架构上的表。

控制器上的原始代码,wkwkwk。account_controller.rb

def destroy
        @account = Account.find(params[:id])
        conn = ActiveRecord::Base.connection
        conn.execute("DROP SCHEMA "+@account.subdomain)
    end

错误信息

ActiveRecord::StatementInvalid in AccountsController#destroy

PG::Error: ERROR:  cannot drop schema subdomain1 because other objects depend on it
DETAIL:  table articles depends on schema subdomain1
table gambarinfos depends on schema subdomain1
table pages depends on schema subdomain1
table redactor_assets depends on schema subdomain1
table schema_migrations depends on schema subdomain1
table usersekolahs depends on schema subdomain1
HINT:  Use DROP ... CASCADE to drop the dependent objects too.
: DROP SCHEMA subdomain1

有任何想法吗?

谢谢

4

1 回答 1

2

问题解决了

将级联添加到conn.execute("DROP SCHEMA "+@account.subdomain+" CASCADE")

于 2012-12-17T19:12:02.193 回答