2013-03-21 142 views
1

在執行rake db時,我總是收到以下錯誤:migrate命令:Rake db:migrate error-SQLite3

rake中止! 發生錯誤,這和所有後來遷移取消: 的SQLite3 ::的SQLException:重複列名:電子郵件:ALTER TABLE 「用戶」 ADD 「電子郵件」 爲varchar(255)DEFAULT '' NOT NULL

我已經還嘗試了命令 - bundle exec rake db:migrate。我跑了 - 追蹤並得到了信息。下面。

**調用分貝:遷移(FIRST_TIME) **調用環境(FIRST_TIME) **執行環境 **調用分貝:load_config(FIRST_TIME) **執行分貝:load_config **執行分貝:遷移 == AddDeviseToUsers:migrating ============================================ === - change_table(:users) rake中止! 發生錯誤,這和所有後來遷移取消:

的SQLite3 ::的SQLException:重複列名:電子郵件:ALTER TABLE 「用戶」 ADD 「電子郵件」 爲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/local/rvm/gems/ruby-1.9.3-p392/gems/activesupport-3.2.12/lib/active_support/ notifications/instrumenter.rb:20:在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日誌' /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:in add_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:in字符串中的塊' /usr/local/rvm/gems/ruby -1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/schema_definitions.rb:468: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:in字符串' /Users/ddorrick/code/onrails/db/migrate/20130321170702_add_devise_to_users.rb :5: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:in change_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:in block in say_with_time' 在/ usr /升ocal/rvm/rubies/ruby​​-1.9.3-p392/lib/ruby​​/1.9.1/benchmark.rb:280:在measure' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:438:in say_with_time' /usr/local/rvm/gems/ruby-1.9.3-p392/寶石/了activerecord-3.2.12/LIB/active_record/migration.rb:458:在method_missing' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:334:in method_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:in向上' 的/ usr/local/rvm/gems/ruby​​-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:410:block (2 levels) in migrate' /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:410: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:in with_connection' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2。 12/lib/active_record/migration.rb:389:在migrate' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:528:in遷移' /usr/local/r vm/gems/ruby​​-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:720:在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:in調用' /usr/local/rvm/gems/ruby-1.9.3- p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:775:在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:in交易' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/ lib/active_record/transactions.rb:208:在transaction' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:775:in ddl_transaction' /usr/local/rvm/gems/ruby-1.9。3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:719:在block in migrate' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:700:in每個' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2。 12/lib/active_record/migration.rb:700:在migrate' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb:570:in以上' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/migration.rb: 551:migrate' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.12/lib/active_record/railties/databases.rake:179:in區塊(2級)' /usr/local/rvm/gems/[email protected]/gems/rake-10.0.3/lib/rake/task.rb:228:in call' /usr/local/rvm/gems/[email protected]/gems/rake-10.0.3/lib/rake/task.rb:228:in執行' /usr/local/rvm/gems/[email protected]/gems/rake-10.0.3/lib/rake/task.rb:223:in each' /usr/local/rvm/gems/[email protected]/gems/rake-10.0.3/lib/rake/task.rb:223:in執行' /usr /local/rvm/gems/[email protected]/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:in mon_synchronize' /usr/local/rvm/gems/ruby [email protected] bal/gems/rake-10.0.3/lib/rake/task.rb:159:在invoke_with_call_chain' /usr/local/rvm/gems/[email protected]/gems/rake-10.0.3/lib/rake/task.rb:152:in中調用' /usr/local/rvm/gems/[email protected]/gems/rake-10.0。 3/lib/rake/application.rb:143:invoke_task' /usr/local/rvm/gems/[email protected]/gems/rake-10.0.3/lib/rake/application.rb:101:in塊(2級),位於top_level' /usr/local/rvm/gems/[email protected]/gems/rake-10.0.3/ lib/rake/application.rb:101:在each' /usr/local/rvm/gems/[email protected]/gems/rake-10.0.3/lib/rake/application.rb:101:in塊中top_level' /usr/local/rvm/gems/[email protected]/gems/rake-10.0.3/lib/rake/application。 rb:110:run_with_threads' /usr/local/rvm/gems/[email protected]/gems/rake-10.0.3/lib/rake/application.rb:95:in top_level' /usr/local/rvm/gems/[email protected]/gems/rake-10.0.3/lib/rake/application.rb:73:in block in run' /usr/local/rvm/gems/[email protected]/gems/rake-10.0.3/lib/rake/application.rb:160:in standard_exception_handling' /usr/local/rvm/gems/[email protected]/gems/rake-10.0.3/lib/rake/application.rb:70:in run' /usr/local/rvm/gems/[email protected]/gems/rake-10.0.3/bin/rake:33:in' /usr/local/rvm/gems /[email protected]/箱/耙:19:在load' /usr/local/rvm/gems/[email protected]/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 =>分貝:遷移

回答

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. 
相關問題