LoginSignup
2
1

More than 5 years have passed since last update.

RailsのMigrationでstringからtextに変更する

Posted at

普通にこんなかんじでいけた。

db/migrate/20161019222407_change_events_memo_to_text.rb
class ChangeEventsMemoToText < ActiveRecord::Migration
  def up
    change_column :events, :memo, :text, default: nil
  end

  def down
    change_column :events, :memo, :string
  end
end

最初 default: nil をつけていなかったが、下記のようなエラーが出たので default: nil をつけてみたら普通に通った。

Mysql2::Error: BLOB, TEXT, GEOMETRY or JSON column 'memo' can't have a default value: ALTER TABLE `events` CHANGE `memo` `memo` text DEFAULT '' NOT NULL
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1