Rails数据库迁移 - 如何删除表? [英] Rails DB Migration - How To Drop a Table?
问题描述
我添加了一个表,我认为我需要,但现在不再计划使用它。如何删除该表?
我已经运行迁移,所以表位于我的数据库中。我认为 rails generate migration
应该能够处理这个问题,但我还没有想出怎么回事。
我试过:
rails生成迁移drop_tablename
,
但是刚刚生成了空
/ div>
您不会总是能够简单地生成迁移,已经拥有您想要的代码。您可以创建一个空迁移,然后使用您需要的代码填充它。
您可以在迁移中找到有关如何完成不同任务的信息:
http://api.rubyonrails.org/ classes / ActiveRecord / Migration.html
更具体地说,您可以使用以下方法了解如何删除表:
drop_table:table_name
I added a table that I thought I was going to need, but now no longer plan on using it. How should I remove that table?
I've already run migrations, so the table is in my database. I figure rails generate migration
should be able to handle this, but I haven't figured out how yet.
I've tried:
rails generate migration drop_tablename
,
but that just generated an empty migration.
What is the "official" way to drop a table in Rails?
You won't always be able to simply generate the migration to already have the code you want. You can create an empty migration and then populate it with the code you need.
You can find information about how to accomplish different tasks in a migration here:
http://api.rubyonrails.org/classes/ActiveRecord/Migration.html
More specifically, you can see how to drop a table using the following approach:
drop_table :table_name
这篇关于Rails数据库迁移 - 如何删除表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!