2013-12-11 250 views
0

我目前正在用ruby 2.0將rails 3.2應用推向heroku。我已經成功將代碼推送到新的heroku服務器,並且現在正在嘗試遷移數據庫,然後對其進行種子處理。Heroku遷移錯誤

當我運行命令

$ heroku run rake:db:migrate 

我得到的錯誤:

Running `rake db:migrate` attached to terminal... up, run.8854 
Connecting to database specified by DATABASE_URL 
Migrating to CreateRoutines (20130720183354) 
Migrating to CreateExercises (20130720183503) 
Migrating to CreateLifts (20130720183601) 
Migrating to CreateInfos (20130723010806) 
Migrating to AddUserIdToRoutine (20130808142746) 
Migrating to AddBodyweighToRoutine (20130810164534) 
Migrating to AddDeviseToUsers (20131003183650) 
== AddDeviseToUsers: migrating =============================================== 
-- change_table(:users) 
rake aborted! 
An error has occurred, this and all later migrations canceled: 

PG::UndefinedTable: ERROR: relation "users" does not exist 
: ALTER TABLE "users" ADD COLUMN "email" character varying(255) DEFAULT '' NOT NULL/app/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/postgresql_adapter.rb:650:in `exec' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/postgresql_adapter.rb:650:in `block in execute' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log' 
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-3.2.13/lib/active_support/notifications/instrumenter.rb:20:in `instrument' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/postgresql_adapter.rb:649:in `execute' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/postgresql_adapter.rb:1022:in `add_column' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/schema_definitions.rb:479:in `block in string' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/schema_definitions.rb:468:in `each' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/schema_definitions.rb:468:in `string' 
/app/db/migrate/20131003183650_add_devise_to_users.rb:5:in `block in up' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/schema_statements.rb:243:in `change_table' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/migration.rb:466:in `block in method_missing' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/migration.rb:438:in `block in say_with_time' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/migration.rb:438:in `say_with_time' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/migration.rb:458:in `method_missing' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/migration.rb:334:in `method_missing' 
/app/db/migrate/20131003183650_add_devise_to_users.rb:3:in `up' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/migration.rb:370:in `up' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/migration.rb:410:in `block (2 levels) in migrate' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/migration.rb:410:in `block in migrate' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:129:in `with_connection' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/migration.rb:389:in `migrate' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/migration.rb:528:in `migrate' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/migration.rb:720:in `block (2 levels) in migrate' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/migration.rb:775:in `call' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/migration.rb:775:in `block in ddl_transaction' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/transactions.rb:208:in `transaction' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/migration.rb:775:in `ddl_transaction' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/migration.rb:719:in `block in migrate' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/migration.rb:700:in `each' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/migration.rb:700:in `migrate' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/migration.rb:570:in `up' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/migration.rb:551:in `migrate' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/railties/databases.rake:193:in `block (2 levels) in <top (required)>' 
Tasks: TOP => db:migrate 
(See full trace by running task with --trace) 

這是某種與設計呢?不知道在這裏做什麼。

也有一些受訪者們一直在問,如果我有一個用戶表:< .BR>

create_table "users", :force => true do |t| 
    t.string "name" 
    t.datetime "created_at",        :null => false 
    t.datetime "updated_at",        :null => false 
    t.string "email",     :default => "", :null => false 
    t.string "encrypted_password",  :default => "", :null => false 
    t.string "reset_password_token" 
    t.datetime "reset_password_sent_at" 
    t.datetime "remember_created_at" 
    t.integer "sign_in_count",   :default => 0 
    t.datetime "current_sign_in_at" 
    t.datetime "last_sign_in_at" 
    t.string "current_sign_in_ip" 
    t.string "last_sign_in_ip" 
    t.string "provider" 
    t.string "uid" 
    end 
+0

? – usha

+0

嘗試[this](http://stackoverflow.com/questions/16974995/heroku-production-error-pgerror-error-relation-users-already-exists-error?rq=1) –

+0

我沒有遷移這是專門爲用戶表,它看起來像Devise在導致錯誤的遷移中爲我做的。這一切都在當地工作。我有一個用戶模型。 – user2184718

回答

0

的錯誤意味着你正在試圖改變表users,但表不存在。

您應該創建表作爲另一個遷移的一部分,或者檢查設計安裝的文檔。我很確定有指示來創建必要的表格而不是改變它。

我給快看at the documentation,我相信你有一個遷移到創建的用戶表的過程是「入門」部分中描述周圍的命令

rails generate devise MODEL 
+0

我有一個用戶模型。這個模型是在我使用Devise時創建的。 – user2184718

+0

問題不在於模型,而在於表格。數據庫中沒有「用戶」表。可能你在/ models文件夾中有一個模型,但這不會在數據庫中創建相應的表格。 –

+0

在導軌控制檯中,我可以看到我的所有用戶。這不是說我有用戶表嗎? – user2184718