内容简介:翻译自:https://stackoverflow.com/questions/20578157/rails-4-how-to-drop-or-remove-join-tables-tables-from-database
)中,我看到要删除表或连接表,可以在命令行中使用以下方法:
drop_table和drop_join_table.
然而,它进一步补充说,必须“提供一个块” – 我不知道执行中的样子.
无论这里是我的问题:如何删除表或删除连接表?
另外,当我说丢弃时,我的意思是从我的数据库中删除它.我知道我无法删除迁移,并且回滚迁移是不明智的,因为它会影响协作工作 – 所以我希望尽可能避免删除迁移文件并回滚迁移.
创建迁移以填充数据库时,我犯了一个错误.我知道如何修改表的列(添加新的,重命名和删除它们).我只是不知道如何清除表格.
感谢您考虑我的问题.
我想从我的数据库中完全删除一个表.我的应用程序在Rails 4上运行.
中定义
它需要表1,表2的名称.示例:您有2个名为categories和products的表,以及名为categories_products的连接表
因此,使用您喜欢的任何名称创建迁移文件,然后编写代码以删除连接表:
def change drop_join_table :categories, :products end
您可以将其他选项传递给drop_join_table方法,这些选项与
create_join_table
相同.请查看此方法以查看更多选项.
例如,如果您的连接表没有遵循约定的名称,例如分类,您可以指定它:
def change drop_join_table :categories, :products, table_name: categorization end
要删除表,使用
drop_table
方法更简单:
def change drop_table :table_name end
其他选项可以传递给drop_table方法,就像
create_table
方法的选项一样
翻译自:https://stackoverflow.com/questions/20578157/rails-4-how-to-drop-or-remove-join-tables-tables-from-database
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Refactoring
Martin Fowler、Kent Beck、John Brant、William Opdyke、Don Roberts / Addison-Wesley Professional / 1999-7-8 / USD 64.99
Refactoring is about improving the design of existing code. It is the process of changing a software system in such a way that it does not alter the external behavior of the code, yet improves its int......一起来看看 《Refactoring》 这本书的介绍吧!