0
votes

When I write rails db:migrate, I get this error:

bundle exec rake db:migrate

== 20161209073230 AddActivationToUsers: migrating ============================= -- add_column(:users, :activation_digest, :string) rake aborted! StandardError: An error has occurred, this and all later migrations canceled:

SQLite3::SQLException: duplicate column name: activation_digest: ALTER TABLE "users" ADD "activation_digest" varchar

Here's my user table:

create_users.rb

class CreateUsers < ActiveRecord::Migration 
  def change
     create_table :users do |t|
     t.string :name
       t.string :email

       t.timestamps null: false
     end 
  end 
end

This is my add_activation_to_users.rb:

class AddActivationToUsers < ActiveRecord::Migration
  def change
    add_column :users, :activation_digest, :string
    add_column :users, :activated, :boolean, default: false
    add_column :users, :activated_at, :datetime
  end
end
2
check your users table, it might be already having a column named activation_digest which you are again trying to add with migration version 20161209073230 .dp7
so that means I don't have to add any migration at all. I'm sorry, I'm totally new to RubyDaniel Lancaster
You can check the existing attributes of your user model from rails console - use User.column_names , if you have already activation_digest , then you don't need to add it again.dp7
Yes it does have activation_digest. So this whole time I tried to migrate something I had all along. ThanksDaniel Lancaster

2 Answers

0
votes

SQLite3::SQLException: duplicate column name: activation_digest: ALTER TABLE "users" ADD "activation_digest" varchar

As the exception suggests, you have already added activation_digest in your users table.

You can check the columns of your users table right from the rails console with User.column_names.

0
votes

You are already having activation_digest in your user table. Please check your schema.rb. If you trying to add new column then you need to deleted already existing one.