Home>
What you don't understand

I am creating a micropost in the rails tutorial exercise, but when I go to root_url

StandardError
An error has occurred, this and all later migrations canceled: SQLite3 :: SQLException: duplicate column name: reset_sent_at


I get an error.
I know that User's reset_sent_at column is duplicated, but I'm not sure where and how it is duplicated. I would be grateful if anyone could give me some advice on how to resolve this error.

Files that are likely to be related
# app/models/user.rb
class User</pre>
<pre><code># app/controllers/password_resets_controller.rb
class PasswordResetsController</pre>
<pre><code># config/routes.rb
Rails.application.routes.draw do
  get'password_resets/new'
  get'password_resets/edit'
  root'static_pages # home'
  get'/ help', to:'static_pages # help'
  get'/ about', to:'static_pages # about'
  get'/ contact', to:'static_pages # contact'
  get'/ signup', to:'users # new'
  get'/ login', to:'sessions # new'
  post'/ login', to:'sessions # create'
  delete'/ logout', to:'sessions # destroy'
  resources: users
  resources: account_activations, only: [: edit]
  resources: password_resets, only: [: new,: create,: edit,: update]
end
# app/mailers/user_mailer.rb
class UserMailer</pre>
<pre><code># 20201223140935_add_reset_to_users.rb
class AddResetToUsers</pre>
<pre><code># 20201223141905_add_reset_sent_at_to_users.rb
class AddResetSentAtToUsers</pre>
<pre><code># db/schema.rb
ActiveRecord :: Schema.define (version: 2020_12_26_033956) do
  create_table "microposts", force:: cascade do | t |
    t.text "content"
    t.integer "user_id", null: false
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
    t.index ["user_id", "created_at"],

 name: "index_microposts_on_user_id_and_created_at"
    t.index ["user_id"],

 name: "index_microposts_on_user_id"
  end
  create_table "users", force:: cascade do | t |
    t.string "name"
    t.string "email"
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: falset.string "password_digest"
    t.string "remember_digest"
    t.boolean "admin", default: false
    t.string "activation_digest"
    t.boolean "activated", default: false
    t.datetime "activated_at"
    t.string "reset_digest"
    t.datetime "reset_sent_at"
    t.index ["email"],

 name: "index_users_on_email", unique: true
  end
  add_foreign_key "microposts", "users"
end
What I tried

rails db: test: prepare
rails db: migrate RAILS_ENV = development
rails db: migrate: reset

20201223140935_add_reset_to_users.rb
20201223141905_add_reset_sent_at_to_users.rb
db/schema.rb

Try commenting out the reset_sent_at part of
=>I was able to access root_url, but an error occurred when transitioning to the password reset screen.

environment

CentOS8

#Gemfile
source'https://rubygems.org'
git_source (: github) {| repo | "https://github.com/#{repo}.git"}
gem'rails', '6.0.3'
gem'bcrypt', '3.1.13'
gem'faker', '2.1.2'
gem'will_paginate', '3.1.8'
gem'bootstrap-will_paginate', '1.0.0'
gem'bootstrap-sass', '3.4.1'
gem'puma', '4.3.6'
gem'sass-rails', '5.1.0'
gem'webpacker', '4.0.7'
gem'turbolinks', '5.2.0'
gem'jbuilder', '2.9.1'
gem'bootsnap', '1.4.5', require: false
group: development,: test do
  gem'sqlite3', '1.4.1'
  gem'byebug', '11 .0.1', platforms: [: mri,: mingw,: x64_mingw]
end
group: development do
  gem'web-console', '4.0.1'
  gem'listen', '3.1.5'
  gem'spring', '2.1.0'
  gem'spring-watcher-listen', '2.0.1'
end
group: test do
  gem'capybara', '3.28.0'
  gem'selenium-webdriver', '3.142.4'
  gem'webdrivers', '4.1.2'
  gem'rails-controller-testing', '1.0.4'
  gem'minitest', '5.11.3'
  gem'minitest-reporters', '1.3.8'
  gem'guard', '2.16.2'
  gem'guard-minitest', '2.4.6'
end
group: production do
  gem'pg', '1.1.4'
end
# On Windows you need to include a tzinfo-data gem for timezone information
gem'tzinfo-data', platforms: [: mingw,: mswin,: x64_mingw,: jruby]
  • Answer # 1

    I don't know if I really need to fix this, but I've found at least one duplicate that clearly seems to be a problem.

    This is likely to be a problem as we are creating columns with the same column name twice for the same table.
    However, in this case, it seems that an error will occur at the time of db: migrate, not during the operation of the application .... I hope it will give you some hints.

Related articles