前提・実現したいこと
最終的な目的:Railsでテーブルを作成し、テストの実施を成功させたい
開発環境:ローカル(Windows10)
Rails5.1チュートリアル挑戦中で、第6章のmigrateが上手く行かずに立ち往生しています。
手順としては下記の通り、モデル作成後、migrateには成功したものの、テストを実行した途端にエラーを吐くという状況です。
C:\Users\snish\environment\sample_app>rails generate model User name:string email:string invoke active_record create db/migrate/20190308140335_create_users.rb create app/models/user.rb invoke test_unit create test/models/user_test.rb create test/fixtures/users.yml C:\Users\snish\environment\sample_app>rails db:migrate == 20190308140335 CreateUsers: migrating ====================================== -- create_table(:users) -> 0.0035s == 20190308140335 CreateUsers: migrated (0.0042s) =============================
発生している問題・エラーメッセージ
C:\Users\snish\environment\sample_app>rails test Migrations are pending. To resolve this issue, run: bin/rails db:migrate RAILS_ENV=test C:\Users\snish\environment\sample_app>rails db:migrate RAILS_ENV=test == 20190308140335 CreateUsers: migrating ====================================== -- create_table(:users) rails aborted! StandardError: An error has occurred, this and all later migrations canceled: SQLite3::SQLException: table "users" already exists: CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar, "email" varchar, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL) C:/Users/snish/environment/sample_app/db/migrate/20190308140335_create_users.rb:3:in `change' bin/rails:4:in `require' bin/rails:4:in `<main>' Caused by: ActiveRecord::StatementInvalid: SQLite3::SQLException: table "users" already exists: CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar, "email" varchar, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL) C:/Users/snish/environment/sample_app/db/migrate/20190308140335_create_users.rb:3:in `change' bin/rails:4:in `require' bin/rails:4:in `<main>' Caused by: SQLite3::SQLException: table "users" already exists C:/Users/snish/environment/sample_app/db/migrate/20190308140335_create_users.rb:3:in `change' bin/rails:4:in `require' bin/rails:4:in `<main>' Tasks: TOP => db:migrate (See full trace by running task with --trace)
試したこと
C:\Users\snish\environment\sample_app>bundle exec rake db:migrate RAILS_ENV=test == 20190308140335 CreateUsers: migrating ====================================== -- create_table(:users) rake aborted! StandardError: An error has occurred, this and all later migrations canceled: SQLite3::SQLException: table "users" already exists: CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar, "email" varchar, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL) C:/Users/snish/environment/sample_app/db/migrate/20190308140335_create_users.rb:3:in `change' Caused by: ActiveRecord::StatementInvalid: SQLite3::SQLException: table "users" already exists: CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar, "email" varchar, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL) C:/Users/snish/environment/sample_app/db/migrate/20190308140335_create_users.rb:3:in `change' Caused by: SQLite3::SQLException: table "users" already exists C:/Users/snish/environment/sample_app/db/migrate/20190308140335_create_users.rb:3:in `change' Tasks: TOP => db:migrate (See full trace by running task with --trace) C:\Users\snish\environment\sample_app>rails db:migrate:reset Permission denied @ unlink_internal - C:/Users/snish/environment/sample_app/db/development.sqlite3 Couldn't drop database 'db/development.sqlite3' rails aborted! Errno::EACCES: Permission denied @ unlink_internal - C:/Users/snish/environment/sample_app/db/development.sqlite3 bin/rails:4:in `require' bin/rails:4:in `<main>' Tasks: TOP => db:drop:_unsafe (See full trace by running task with --trace) C:\Users\snish\environment\sample_app>rails db:migrate C:\Users\snish\environment\sample_app>rails test Migrations are pending. To resolve this issue, run: bin/rails db:migrate RAILS_ENV=test
補足情報(FW/ツールのバージョンなど)
ruby 2.4.5
Rails 5.1.6
sqlite3 1.3.13
以上になります。
不足情報等あればすぐに追記しますので、よろしくお願いします。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/03/09 07:05
2019/03/09 07:13
2019/03/09 07:44