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.

deviceを入れているときに、rails db:migrateできなくて詰まった話

0
Last updated at Posted at 2021-02-21

今回起こったことを話すと、railsにいれていたgemであるdeviceを使ってログイン機能を実装しようと思ったら、rails db:migrateできなくなってしまいました

解決策

1つ目

docker-compose run --rm web rails d devise User

を実行してから、

docker-compose run web rails d devise:views

を打ち込んで実行して、

docker-compose run --rm web rails g controller Pages index show

を実行、ただし、このときにcontrollerを作成していなければ、この限りではない
この工程をスキップした場合は、これは行わなくていい

docker-compose run --rm web rails d devise:uninstall

を実行して、deviceをアンイストールした後に、gemfileの、

gem 'device'

を削除

そして、

完了

ってなるはずだったんですけど、ここで致命的なミスをやらかしてました。
それは何かって言うと、最初の工程である、

docker-compose run --rm web rails d devise User

これをしないで、完了したぜイェイとか思ってたんですけどこれが間違いでしたね、、、

これをしないで、deviceを再インストールしたら、

db/migrate/20210221123320_add_devise_to_users.rb
# frozen_string_literal: true

class AddDeviseToUsers < ActiveRecord::Migration[6.0]
  def self.up
    change_table :users do |t|
      ## Database authenticatable
      t.string :email,              null: false, default: ""
      t.string :encrypted_password, null: false, default: ""

# 省略

五行目の

def self.up
    change_table :users do |t|

change_tableになってるのでこれは間違いですね。

def self.up
    create_table :users do |t|

になおして

docker-compose run web rails db:migrate

をしたら無事migrationできました。

ふぅ

参考記事

ご指摘などありましたらコメント欄によろしくお願いします。

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?