如何在不迁移的情况下从rails控制台重命名列?

时间:2022-04-09 20:44:58

I would like to rename a table column from the rails console without writing any migration.

我想从rails控制台重命名表列而不编写任何迁移。

how can I do that?

我怎样才能做到这一点?

3 个解决方案

#1


5  

rails dbconsole
ALTER TABLE name RENAME column TO column

#2


23  

I opted to run this from the console:

我选择从控制台运行它:

ActiveRecord::Base.connection.rename_column :tablename, :old_column_name, :new_column_name

#3


0  

  1. you run in console: rails g migration ChangeColName
  2. 你在控制台中运行:rails g migration ChangeColName

  3. you edit the file db/migrate/"timestamp"_change_col_name.rb insert in def change -

    你在def def中编辑文件db / migrate /“timestamp”_change_col_name.rb insert

    rename_column :tablename, :old_column_name, :new_column_name -save
    
  4. you run in console: rake db:migrate :-)

    你在控制台中运行:rake db:migrate :-)

#1


5  

rails dbconsole
ALTER TABLE name RENAME column TO column

#2


23  

I opted to run this from the console:

我选择从控制台运行它:

ActiveRecord::Base.connection.rename_column :tablename, :old_column_name, :new_column_name

#3


0  

  1. you run in console: rails g migration ChangeColName
  2. 你在控制台中运行:rails g migration ChangeColName

  3. you edit the file db/migrate/"timestamp"_change_col_name.rb insert in def change -

    你在def def中编辑文件db / migrate /“timestamp”_change_col_name.rb insert

    rename_column :tablename, :old_column_name, :new_column_name -save
    
  4. you run in console: rake db:migrate :-)

    你在控制台中运行:rake db:migrate :-)