0
0

More than 3 years have passed since last update.

RailsのDBマイグレーションの細々したメモ

Posted at

railsのマイグレーションのファイルにexecute "生SQl"を生SQLを入れられる

    execute 'UPDATE posts SET start_at = created_at WHERE start_at IS NULL'
    change_column_null :posts, :start_at, false

NOT NULL制約をマイグレーションで加える際は

    change_column_null :customer_news, :name, false, '既存のnullを置き換える値', default: 'デフォルトさん'

MySQL5.6ではtext型、blob型のカラムのNOT NULL制約のデフォルト値を設定できない

  • ''(空文字)がデフォルトになりそう??
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