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 5 years have passed since last update.

Devise導入でハマった件

0
Last updated at Posted at 2020-08-20

Ruby on Railsで構築したWebサイトにログイン機能を実装すべく、Deviseを導入したらガッツリはまって1日無駄にしたので備忘。

環境

・Ruby 2.6.3 ・Rails 6.0.3.2 ・MySQL

事象

Deviseをinstall後に、以下のコマンドでuserモデルを作成する。
rails g devise user
rails db:migrate

以下のメッセージが表示される

/usr/local/src/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-6.0.0/lib/rails/app_loader.rb:53: warning: Insecure world writable dir /home/rails in PATH, mode 040777
== 20200820093209 DeviseCreateUsers: migrating ================================
-- create_table(:users)
   -> 0.0270s
-- add_index(:users, :email, {:unique=>true})
rails aborted!
StandardError: An error has occurred, all later migrations canceled:
Mysql2::Error: Specified key was too long; max key length is 767 bytes

よくわからなかったので以下のコマンドでモデルを削除してリトライしてみることに

//モデル削除
rails d devise user
//モデル再作成
rails g decise user
//Migrate
rails db:migrate

そしたらこんなエラーが発生して、先のも進めず前にも戻れず泥沼にハマった。

Mysql2::Error: Table 'users' already exists

原因と解決法

⓵モデルが上手く削除されていない!

モデルの削除が不完全で、DB上から完全にテーブルが削除されていなかった。
https://qiita.com/Kuragasaki/items/7d98cf29341611fb189a

⓶テーブル作成時の設定を変更

DB作成時のカラムサイズが制限を超えているらしい。
Railsではカラムサイズを自動で判断するのだが文字コードによっては計算が上手くはまらず、MySQLの制限をオーバーしている模様。自動判断の設定を変更して制限以内に収まるようにする。
https://qiita.com/terufumi1122/items/9ea764618eba01144e09

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?