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.

【RubyonRails】no such tableのエラー

Posted at

【RubyonRails】no such tableのエラー

Devise導入時にこんなエラーが、

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

SQLite3::SQLException: no such table: users: ALTER TABLE "users" ADD "email" varchar DEFAULT '' NOT 
NULL
C:/Users/sample/db/migrate/20210315111515_add_devise_to_users.rb:7:in `block in up'      
bin/rails:4:in `<main>'

Caused by:
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such table: users: ALTER TABLE "users" ADD "email" varchar DEFAULT '' NOT NULL
C:/Users/sample/db/migrate/20210315111515_add_devise_to_users.rb:7:in `block in up'      
C:/Users/sample/db/migrate/20210315111515_add_devise_to_users.rb:5:in `up'

Caused by:
SQLite3::SQLException: no such table: users
C:/Users/sample/db/migrate/20210315111515_add_devise_to_users.rb:7:in `block in up'      
C:/Users/sample/db/migrate/20210315111515_add_devise_to_users.rb:5:in `up'
bin/rails:4:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)

usersのテーブルが見つかりませんってことっぽい
でも確認したらsersテーブルあるんだよなぁ

なのでもう一度

terminal
>rails g devise user
>rails db:migrate

を実行。
治りませんでした。

なんでだろうと思い新しくプロジェクトを作成しrails db:migrateをするとそちらではできました
何が違うのかなとfileをみていたらエラーが起こる方は

20210315111515_add_devise_to_users.rb
class AddDeviseToUsers < ActiveRecord::Migration[5.2]
  def self.up
    change_table :users do |t|

と記述してあり
エラーが起こらない方は

20210315115722_devise_create_users.rb
class DeviseCreateUsers < ActiveRecord::Migration[5.2]
  def change
    create_table :users do |t|

と記述してあり、change_tableをcreate_tableに直したら実行できました!!!!
このエラーに結構苦戦したため備忘録として残しておきます

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?