我试图改变一行schema.rb(t.string必须变成t.text)但是我无法直接通过该文件更改它,因为当我使用rake db:migrate时,更改将恢复到之前的状态.
我该如何更改该字符串?
编辑:如果我没有误解某些东西,我必须编辑db / migrate中的文件.在我的情况下是2010110801532_create_posts.rb,我究竟要把change_column放在哪里?
这是我的2010110801532_create_posts.rb
class CreatePosts < ActiveRecord::Migration def self.up create_table :posts do |t| t.string :nome t.string :titolo t.text :contenuto t.timestamps end end def self.down drop_table :posts end end
解决方法
一步步:
首先,生成一个新的迁移:
./script/generate migration change_string_to_text
在生成的迁移文件nnnnnnnnnnn_change_string_to_text.rb中,您需要添加以下行:
change_column :table_name,:column_name,:text
然后执行rake migrate以将更改应用于数据库.