1

I have been getting this error when I run bundle exec rake db:migrate for a basic RoR website. I am a beginner and found similar errors on this site and Treehouse but nothing with the specific second half of this error (from the NOT NULLC onward). I am still not sure how to resolve this - can anyone advise? I am running this on windows.

SQLite3::SQLException: duplicate column name: email: ALTER TABLE "users" ADD "em
ail" varchar(255) DEFAULT '' NOT NULLC:/Sites/code/omrails-master/db/migrate/201
30804201341_add_devise_to_users.rb:5:in `block in up'

1 Answer 1

1

The SQlite error is showing that you already create email field to users table.

ADD "email" varchar(255) DEFAULT '' NOT NULL. so try to use "different column name"

or remove old migration.

def change 
  remove_column  :users, :email, <type>
end

after that use this migration

def up
  add_column :users, :email, :string
end


def down
  remove_column :users, :email, :string
end
Sign up to request clarification or add additional context in comments.

9 Comments

Where do I put this code? In the user.rb file? I typed the first code into my models/user.rb file and then ran bundle exec rake db:migrate and got the same error. What do I need to try differently for the first part>
you need to do migration or if you are new for rails ....read some migration concepts about change, up and down. guides.rubyonrails.org/migrations.html
hmm...would you be able to advise further...I put the above code into the speficied db migrate file. Then I typed bundle exec db:migrate but it did not seem to work.
"SQLite3::SQLException: duplicate column name: email:" so use SQLite database browser (if it's not in pc download it) and check in user table, email column is already there or not. If email column is not exist then run up and down migration and if email column is already there then try to remove it and recreate using change migration. I already mention read about some migration concepts for add/remove a column.
Here is the link to the same question I re-asked. There is no test.sqlite3 database. I downloaded SQLITE database browser. I am struggling with actual creation of this but if you can advise that would be appreciated (I am working on this and trying to figure it out as well). stackoverflow.com/questions/18087481/…
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.