gpt4 book ai didi

ruby-on-rails-3 - 通过 Controller Rails 删除或删除 Schema Postgresql

转载 作者:行者123 更新时间:2023-12-02 02:09:51 25 4
gpt4 key购买 nike

我有一个带有 postgresql 的 Multi-Tenancy 应用程序轨道,我想删除架构(架构名称 = 子域)并删除架构上的表。

Controller 上的原始代码,wkwkwk。accounts_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

有什么想法吗?

谢谢

最佳答案

问题解决了

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

关于ruby-on-rails-3 - 通过 Controller Rails 删除或删除 Schema Postgresql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13397994/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com