LoginSignup
0
0

More than 1 year has passed since last update.

MySQL カラム エラー

Posted at

はじめに

deviseを用いてユーザー管理機能の実装中にエラーが発生しました。

エラー内容

migrateファイルにてテーブル作成中。
↓以下のようにカラムの設定を実装した。

    create_table :users do |t|
      ## Database authenticatable
      t.string :email,              null: false, default: ""
      t.string :encrypted_password, null: false, default: ""
      t.string :name,               null: false, default: ""
      t.text   :profile,            null: false, default: ""
      t.text   :occupation,         null: false, default: ""
      t.text   :position,           null: false, default: ""

rails db:migrate実行後

Error: BLOB, TEXT, GEOMETRY or JSON column 'profile' can't have a default value

上記のエラー文がターミナル上に表示された。

問題解決の過程

ネットで調べたところ
MySQLでBLOB/text型にはデフォルト設定ができないとのこと。

そのためtext型のデフォルト設定を削除し
↓以下のコーティングで再実行

 create_table :users do |t|
      ## Database authenticatable
      t.string :email,              null: false, default: ""
      t.string :encrypted_password, null: false, default: ""
      t.string :name,               null: false, default: ""
      t.text   :profile,            null: false
      t.text   :occupation,         null: false
      t.text   :position,           null: false

以上でテーブルの設定が完了した。

まとめ

MySQLではtext型でデフォルト設定ができない。

最後まで閲覧して頂きありがとうございました。

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