gpt4 book ai didi

ruby-on-rails - Rails 迁移 : indexes on a renamed table

转载 作者:行者123 更新时间:2023-12-03 23:17:30 24 4
gpt4 key购买 nike

我创建了一个表并为其添加了索引。
在第二次迁移时,我重命名了该表。
指数会继续工作吗?

最佳答案

rails 3

不,您需要自己处理索引,因为索引基于表名。例如:

remove_index :old_table_name, :column_name
rename_table :old_table_name, :new_table_name
add_index :new_table_name, :column_name

rails 4+

来自 the Rails 4 upgrade guide :

In Rails 4.0 when a column or a table is renamed the related indexes are also renamed. If you have migrations which rename the indexes, they are no longer needed.

关于ruby-on-rails - Rails 迁移 : indexes on a renamed table,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18701173/

24 4 0