4
1

More than 3 years have passed since last update.

【Rails Error】No such table userと言われた

Posted at

【Rails Error】No such table userと言われた

あるとき、Deviseを導入した時に、こんなエラーが出た

terminal
> rails db:migrate
== 20190905110927 AddDeviseToUsers: migrating =================================
-- change_table(:users)
rails aborted!
StandardError: An error has occurred, this and all later migrations canceled:

SQLite3::SQLException: no such table: users:

Userテーブルがないとお!
とはいえrails g devise userをしてもrails g model userをしても反応しないじゃないか!

無いからダメって言われて、じゃあ作ろうとしたら怒るってどんなツンデレよ..

あれこれ調べていると、

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

なんかこのコードの3行目にchange_tableってあるぞ
なんか怪しい。
普通、正常にDeviseを導入できれば

20200513025737_devise_create_users.rb
class DeviseCreateUsers < ActiveRecord::Migration[6.0]
  def change
    create_table :users do |t|
      ## Database authenticatable
      t.string :email,              null: false, default: ""
      t.string :encrypted_password, null: false, default: ""

このように3行目はcreate_tableのはずだ

試しにchange_tableをcreate_tableに変えると通った!!!!!!!
皆さんも同じように詰まれば試してみてください!

4
1
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
4
1