前提・実現したいこと
ActiveRecord::PendingMigrationErrorが起きたのでrake db:migrateを実行したい。
発生している問題・エラーメッセージ
rake db:migrateを実行すると以下のエラーが起きてしまう。
StandardError: An error has occurred, all later migrations canceled: Mysql2::Error: Table 'withme_development.users' doesn't exist: ALTER TABLE `users` ADD `email` varchar(255) DEFAULT '' NOT NULL /Users/takagitoshinari/withme/db/migrate/20190720085314_add_devise_to_users.rb:7:in `block in up' /Users/takagitoshinari/withme/db/migrate/20190720085314_add_devise_to_users.rb:5:in `up' Caused by: ActiveRecord::StatementInvalid: Mysql2::Error: Table 'withme_development.users' doesn't exist: ALTER TABLE `users` ADD `email` varchar(255) DEFAULT '' NOT NULL /Users/takagitoshinari/withme/db/migrate/20190720085314_add_devise_to_users.rb:7:in `block in up' /Users/takagitoshinari/withme/db/migrate/20190720085314_add_devise_to_users.rb:5:in `up' Caused by: Mysql2::Error: Table 'withme_development.users' doesn't exist /Users/takagitoshinari/withme/db/migrate/20190720085314_add_devise_to_users.rb:7:in `block in up' /Users/takagitoshinari/withme/db/migrate/20190720085314_add_devise_to_users.rb:5:in `up' Tasks: TOP => db:migrate (See full trace by running task with --trace)
該当のソースコード(20190720085314_add_devise_to_users.rb)
ruby
1# frozen_string_literal: true 2 3class AddDeviseToUsers < ActiveRecord::Migration[5.2] 4 def self.up 5 change_table :users do |t| 6 ## Database authenticatable 7 t.string :email, null: false, default: "" 8 t.string :encrypted_password, null: false, default: "" 9 t.string :nickname, null: false, default: "" 10 11 ## Recoverable 12 t.string :reset_password_token 13 t.datetime :reset_password_sent_at 14 15 ## Rememberable 16 t.datetime :remember_created_at 17 18 ## Trackable 19 # t.integer :sign_in_count, default: 0, null: false 20 # t.datetime :current_sign_in_at 21 # t.datetime :last_sign_in_at 22 # t.string :current_sign_in_ip 23 # t.string :last_sign_in_ip 24 25 ## Confirmable 26 # t.string :confirmation_token 27 # t.datetime :confirmed_at 28 # t.datetime :confirmation_sent_at 29 # t.string :unconfirmed_email # Only if using reconfirmable 30 31 ## Lockable 32 # t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts 33 # t.string :unlock_token # Only if unlock strategy is :email or :both 34 # t.datetime :locked_at 35 36 37 # Uncomment below if timestamps were not included in your original model. 38 # t.timestamps null: false 39 end 40 41 add_index :users, :email, unique: true 42 add_index :users, :reset_password_token, unique: true 43 # add_index :users, :confirmation_token, unique: true 44 # add_index :users, :unlock_token, unique: true 45 end 46 47 def self.down 48 # By default, we don't want to make any assumption about how to roll back a migration when your 49 # model already existed. Please edit below which fields you would like to remove in this migration. 50 raise ActiveRecord::IrreversibleMigration 51 end 52end 53
該当のソースコード(user.rb)
class User < ApplicationRecord # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :validatable end
試したこと
rake db:migrate:resetを実行してみたがタイトルと同様のエラーが発生した。
補足情報(FW/ツールのバージョンなど)
ruby 2.3.1p112
Rails 5.2.3

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/07/20 14:49
2019/07/21 11:52
2019/07/31 12:45