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
- you run in console:
rails g migration ChangeColName
-
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
-
you run in console:
rake db:migrate
:-)你在控制台中运行:rake db:migrate :-)
你在控制台中运行:rails g migration ChangeColName
#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
- you run in console:
rails g migration ChangeColName
-
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
-
you run in console:
rake db:migrate
:-)你在控制台中运行:rake db:migrate :-)
你在控制台中运行:rails g migration ChangeColName