Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
是否有 Rails gem、插件或其他方法可以自动从您的数据库和架构中添加或删除所有 RI 约束?还是以每张桌子为基础?就像是:
remove_all_foreign_key_constraints('comments')
没有我知道的宝石/插件。
虽然这很棘手,因为 rails(和大多数适配器)假设引用完整性是通过应用程序的关联来维护的。
如果是这种情况(关联在模型中维护),那么您可以编写一个小脚本,根据模型的关联构造所需的 SQL 语句。
关联反射可能会有所帮助:
http://api.rubyonrails.org/classes/ActiveRecord/Reflection/ClassMethods.html#method-i-reflect_on_all_associations