我需要在不删除数据库的情况下删除数据库中的所有表,因为该数据库的用户没有创建数据库的权限。
删除所有表但不删除实际数据库的最佳方法是什么?
此外,我们使用 rake db:seed
将一些条目添加到其中一个表中,因此我不想使用种子文件。
最佳答案
这是我在查看 Truncate 方法后最终想出的解决方案。
namespace :db do
desc "Erase all tables"
task :clear => :environment do
conn = ActiveRecord::Base.connection
tables = conn.tables
tables.each do |table|
puts "Deleting #{table}"
conn.drop_table(table)
end
end
end
关于ruby-on-rails - rake 数据库 :reset Drop all tables but not database,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23226900/