重命名导轨中的表 [英] Renaming table in rails

查看:34
本文介绍了重命名导轨中的表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想重命名一个表...(任何表.)

I want to rename a table... (any table.)

我试过这行代码:

ActiveRecord::ConnectionAdapters::SchemaStatements.rename_table(old_name, new_name)

这就是奇怪的事情.我知道我第一次让它工作,但现在我收到这个错误:未定义方法`rename_table' for ActiveRecord::ConnectionAdapters::SchemaStatements:Module

Here's the weird thing. I know I got it working the first time, but now I get this error: undefined method `rename_table' for ActiveRecord::ConnectionAdapters::SchemaStatements:Module

有什么我需要设置的吗?

Was there something I need to set?

推荐答案

您通常会在迁移中执行此类操作:

You would typically do this sort of thing in a migration:

class RenameFoo < ActiveRecord::Migration
  def self.up
    rename_table :foo, :bar
  end

  def self.down
    rename_table :bar, :foo
  end
end

这篇关于重命名导轨中的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆