0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

`rails generate migration` コマンドで長さ制限付きのstring型カラムを追加したいとき

Posted at

string{n} のようにすればよい。

$ rails g migration AddNameToUsers name:string{30}

生成されるマイグレーションファイルは以下のようになる

class AddNameToUsers < ActiveRecord::Migration[6.0]
  def change
    add_column :users, :name, :string, limit: 30
  end
end

他にuniqやindexも使えるのだが limit だけ何故か忘れてしまうのでメモ

参考

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?