1

I keep getting the following error when doing the rake db:migrate command:

rake aborted! An error has occurred, this and all later migrations canceled: SQLite3::SQLException: duplicate column name: email: ALTER TABLE "users" ADD "email" varchar(255) DEFAULT '' NOT NULL

I've also tried the command - bundle exec rake db:migrate. I ran with --trace and got the info. below.

** Invoke db:migrate (first_time) ** Invoke environment (first_time) ** Execute environment ** Invoke db:load_config (first_time) ** Execute db:load_config ** Execute db:migrate == AddDeviseToUsers: migrating =============================================== -- change_table(:users) rake aborted! An error has occurred, this and all later migrations canceled:

SQLite3::SQLException: duplicate column name: email: ALTER TABLE "users" ADD "email" varchar(255) DEFAULT '' NOT NULL /usr/local/rvm/gems/ruby-1.9.3-p392/gems/sqlite3-1.3.7/lib/sqlite3/database.rb:91:in initialize' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/sqlite3-1.3.7/lib/sqlite3/database.rb:91:innew' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/sqlite3-1.3.7/lib/sqlite3/database.rb:91:in prepare' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/sqlite3-1.3.7/lib/sqlite3/database.rb:134:inexecute' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/connection_adapters/sqlite_adapter.rb:278:in block in execute' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract_adapter.rb:280:inblock in log' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activesupport-3.2.12/lib/active_support/notifications/instrumenter.rb:20:in instrument' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract_adapter.rb:275:inlog' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/connection_adapters/sqlite_adapter.rb:278:in execute' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/schema_statements.rb:264:inadd_column' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/connection_adapters/sqlite_adapter.rb:400:in add_column' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/schema_definitions.rb:479:inblock in string' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/schema_definitions.rb:468:in each' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/schema_definitions.rb:468:instring' /Users/ddorrick/code/onrails/db/migrate/20130321170702_add_devise_to_users.rb:5:in block in up' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/schema_statements.rb:243:inchange_table' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:466:in block in method_missing' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:438:inblock in say_with_time' /usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/benchmark.rb:280:in measure' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:438:insay_with_time' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:458:in method_missing' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:334:inmethod_missing' /Users/ddorrick/code/onrails/db/migrate/20130321170702_add_devise_to_users.rb:3:in up' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:370:inup' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:410:in block (2 levels) in migrate' /usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/benchmark.rb:280:inmeasure' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:410:in block in migrate' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_pool.rb:129:inwith_connection' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:389:in migrate' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:528:inmigrate' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:720:in block (2 levels) in migrate' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:775:incall' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:775:in block in ddl_transaction' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/database_statements.rb:192:intransaction' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/transactions.rb:208:in transaction' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:775:inddl_transaction' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:719:in block in migrate' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:700:ineach' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:700:in migrate' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:570:inup' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:551:in migrate' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/railties/databases.rake:179:inblock (2 levels) in ' /usr/local/rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.0.3/lib/rake/task.rb:228:in call' /usr/local/rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.0.3/lib/rake/task.rb:228:inblock in execute' /usr/local/rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.0.3/lib/rake/task.rb:223:in each' /usr/local/rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.0.3/lib/rake/task.rb:223:inexecute' /usr/local/rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.0.3/lib/rake/task.rb:166:in block in invoke_with_call_chain' /usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/monitor.rb:211:inmon_synchronize' /usr/local/rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.0.3/lib/rake/task.rb:159:in invoke_with_call_chain' /usr/local/rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.0.3/lib/rake/task.rb:152:ininvoke' /usr/local/rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.0.3/lib/rake/application.rb:143:in invoke_task' /usr/local/rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.0.3/lib/rake/application.rb:101:inblock (2 levels) in top_level' /usr/local/rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.0.3/lib/rake/application.rb:101:in each' /usr/local/rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.0.3/lib/rake/application.rb:101:inblock in top_level' /usr/local/rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.0.3/lib/rake/application.rb:110:in run_with_threads' /usr/local/rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.0.3/lib/rake/application.rb:95:intop_level' /usr/local/rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.0.3/lib/rake/application.rb:73:in block in run' /usr/local/rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.0.3/lib/rake/application.rb:160:instandard_exception_handling' /usr/local/rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.0.3/lib/rake/application.rb:70:in run' /usr/local/rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.0.3/bin/rake:33:in' /usr/local/rvm/gems/ruby-1.9.3-p392@global/bin/rake:19:in load' /usr/local/rvm/gems/ruby-1.9.3-p392@global/bin/rake:19:in' /usr/local/rvm/gems/ruby-1.9.3-p392/bin/ruby_noexec_wrapper:14:in eval' /usr/local/rvm/gems/ruby-1.9.3-p392/bin/ruby_noexec_wrapper:14:in' Tasks: TOP => db:migrate

1 Answer 1

0
First of all, if you're using devise for authentication,email field is provided by default. The source for the error is: "The email field is also present in users table. That's why whenever you're run db:migrate it shows duplicate column error.

So drop the users table by giving command ActiveRecord::Migration.drop_table(:users)"  in rails console.

Then, give  rails g model user user_name:string mobile_number:integer

Hope it will helps. 
Sign up to request clarification or add additional context in comments.

Comments

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.