1

执行 rake db:migrate 命令时,我不断收到以下错误:

耙中止!发生错误,此迁移和所有后续迁移已取消:SQLite3::SQLException:重复列名:电子邮件:ALTER TABLE "users" ADD "email" varchar(255) DEFAULT '' NOT NULL

我也试过命令 - bundle exec rake db:migrate。我跑了 --trace 并得到了信息。以下。

** 调用 db:migrate (first_time) ** 调用环境 (first_time) ** 执行环境 ** 调用 db:load_config (first_time) ** 执行 db:load_config ** 执行 db:migrate == AddDeviseToUsers: 迁移 ==== ============================================--change_table(:users)耙中止!发生错误,此迁移和所有后续迁移均已取消:

SQLite3::SQLException:重复列名:电子邮件: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:在initialize' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/sqlite3-1.3.7/lib/sqlite3/database.rb:91:in新的'/usr/local/rvm/gems/ruby-1.9.3-p392/gems/sqlite3-1.3.7/lib/sqlite3/database.rb: 91:在prepare' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/sqlite3-1.3.7/lib/sqlite3/database.rb:134:in执行中'/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/connection_adapters/sqlite_adapter.rb:278 :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:in在日志中的块'/usr/本地/rvm/gems/ruby-1.9.3-p392/gems/activesupport-3.2.12/lib/active_support/notifications/instrumenter.rb:20:in log' /usr/local/rvm/gems/ruby-1.9 instrument' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract_adapter.rb:275:in。 3-p392/gems/activerecord-3.2.12/lib/active_record/connection_adapter/sqlite_adapter.rb:278:inexecute' /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:inmethod_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:inblock 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:in事务' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/transactions.rb:208:intransaction' /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:incall' /usr/local/rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.0.3/lib/rake/task.rb:228:in块执行'/usr/local/rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.0.3/lib/rake/task.rb:223:在each' /usr/local/rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.0.3/lib/rake/task.rb:223:in执行'/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:ininvoke_with_call_chain' /usr/local/rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.0.3/lib/rake/task.rb:152:in调用' /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' 任务:TOP => db:migrate

4

1 回答 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. 
于 2015-07-12T04:09:15.833 回答