ActiveRecord::PendingMigrationError
解決したいこと
簡易SNSをrailsで作成している初学者です
localhostに接続できずに悩んでいます
エラー文のrails db:migrate RAILS_ENV=developmentを試してみても改善されませんでした。
サーバーと切断される前にdb:resetなどdbの編集を行ったのが原因だと思い、db:setupを実行してみても改善されませんでした。
どこに問題があるのかわからず困っているのでアドバイスいただけると幸いですWindows
環境
Windows10
Rails 5.2.4.5
発生している問題・エラー
ActiveRecord::PendingMigrationError
Migrations are pending. To resolve this issue, run: bin/rails db:migrate RAILS_ENV=development
Extracted source (around line #579):
# Raises <tt>ActiveRecord::PendingMigrationError</tt> error if any migrations are pending.
def check_pending!(connection = Base.connection)
raise ActiveRecord::PendingMigrationError if connection.migration_context.needs_migration?
end
def load_schema_if_pending!
該当するソースコード
rails dbconsole
SQLite version 3.34.1 2021-01-20 14:10:07
Enter ".help" for usage hints.
sqlite> .tables
ar_internal_metadata schema_migrations
movies users
sqlite> .schema
CREATE TABLE IF NOT EXISTS "schema_migrations" ("version" varchar NOT NULL PRIMARY KEY);
CREATE TABLE IF NOT EXISTS "ar_internal_metadata" ("key" varcharT NULL, "updated_at" datetime NOT NULL);
CREATE TABLE IF NOT EXISTS "movies" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "content" text, "created_at" datetime NOT
NULL, "updated_at" datetime NOT NULL);
CREATE TABLE sqlite_sequence(name,seq);
CREATE TABLE IF NOT EXISTS "users" ("id" integer PRIMARY KEY AUTt" datetime NOT NULL, "updated_at" datetime NOT NULL, "image_name" varchar);
sqlite> .quit
PS C:\Users\shunt\SANGOO_app> rails db:status
rails aborted!
Don't know how to build task 'db:status' (See the list of available tasks with `rails --tasks`)
Did you mean? db:setup
bin/rails:4:in `<main>'
(See full trace by running task with --trace)
PS C:\Users\shunt\SANGOO_app> rails db:setup
Database 'db/development.sqlite3' already exists
Database 'db/test.sqlite3' already exists
-> 0.2615s
-- create_table("users", {:force=>:cascade})
-> 0.1959s
-- create_table("movies", {:force=>:cascade})
-> 0.2261s
-- create_table("users", {:force=>:cascade})
-> 0.1538s
You have 1 pending migration:
20210329061844 AddImageNameToUsers
Run `rails db:migrate` to update your database then try again.
PS C:\Users\shunt\SANGOO_app> rails db:migrate
== 20210329061844 AddImageNameToUsers: migrating ==============================
-- add_column(:users, :image_name, :string)
rails aborted!
StandardError: An error has occurred, this and all later migrations canceled:
SQLite3::SQLException: duplicate column name: image_name: ALTER
TABLE "users" ADD "image_name" varchar
C:/Users/shunt/SANGOO_app/db/migrate/20210329061844_add_image_name_to_users.rb:3:in `change'
bin/rails:4:in `<main>'
Caused by:
ActiveRecord::StatementInvalid: SQLite3::SQLException: duplicate column name: image_name: ALTER TABLE "users" ADD "image_name" varchar
me_to_users.rb:3:in `change'
bin/rails:4:in `<main>'
Caused by:
SQLite3::SQLException: duplicate column name: image_name
C:/Users/shunt/SANGOO_app/db/migrate/20210329061844_add_image_nabin/rails:4:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
rails aborted!
Don't know how to build task 'db:status' (See the list of available tasks with `rails --tasks`)
Did you mean? db:setup
bin/rails:4:in `<main>'
(See full trace by running task with --trace)
PS C:\Users\shunt\SANGOO_app> ruby version
Traceback (most recent call last):
C:\Ruby27-x64\bin\ruby.exe: No such file or directory -- version (LoadError)
PS C:\Users\shunt\SANGOO_app> rails db:setup
Database 'db/development.sqlite3' already exists
Database 'db/test.sqlite3' already exists
-> 0.2929s
-- create_table("users", {:force=>:cascade})
-> 0.3336s
-- create_table("movies", {:force=>:cascade})
-> 0.1725s
-- create_table("users", {:force=>:cascade})
-> 0.1768s
You have 1 pending migration:
20210329061844 AddImageNameToUsers
Run `rails db:migrate` to update your database then try again.
PS C:\Users\shunt\SANGOO_app> rails db:migrate
== 20210329061844 AddImageNameToUsers: migrating ==============================
-- add_column(:users, :image_name, :string)
rails aborted!
StandardError: An error has occurred, this and all later migrations canceled:
SQLite3::SQLException: duplicate column name: image_name: ALTER TABLE "users" ADD "image_name" varchar
C:/Users/shunt/SANGOO_app/db/migrate/20210329061844_add_image_name_to_users.rb:3:in `change'
bin/rails:4:in `<main>'
C:/Users/shunt/SANGOO_app/db/migrate/20210329061844_add_image_name_to_users.rb:3:in `change'
bin/rails:4:in `<main>'
Caused by:
SQLite3::SQLException: duplicate column name: image_name
C:/Users/shunt/SANGOO_app/db/migrate/20210329061844_add_image_name_to_users.rb:3:in `change'
bin/rails:4:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
0