2015-09-05 41 views
0

我在第7章Michael Harl Rails Tutorial的末尾,执行heroku run rake db:migrate时遇到问题。这是说'用户'不存在。我试图重置heroku数据库,然后迁移但仍然是相同的错误。任何想法将不胜感激。请参阅下面的完整错误跟踪。迈克尔哈特教程第7章 - PG :: UndefinedTable:错误:关系“用户”不存在

下面是迁移文件:

class AddPasswordDigestToUsers < ActiveRecord::Migration 
     def change 
     add_column :users, :password_digest, :string 
     end 
    end 

和架构:

ActiveRecord::Schema.define(version: 20150824215943) do 

    create_table "users", force: :cascade do |t| 
    t.string "name" 
    t.string "email" 
    t.datetime "created_at",  null: false 
    t.datetime "updated_at",  null: false 
    t.string "password_digest" 
    end 

end 

和用户模型:

class User < ActiveRecord::Base 
    before_save { email.downcase! } 
    validates :name, presence: true, length: { maximum: 50 } 
    VALID_EMAIL_REGEX = /\A[\w+\-.][email protected][a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i 
    validates :email, presence: true, 
        format:  { with: VALID_EMAIL_REGEX }, 
        uniqueness: { case_sensitive: false } 
    has_secure_password 
    validates :password, presence: true, length: { minimum: 6 } 

end 

完整的错误跟踪:

Running `rake db:migrate --trace` attached to terminal... up, run.1726 
** Invoke db:migrate (first_time) 
** Invoke environment (first_time) 
** Execute environment 
** Invoke db:load_config (first_time) 
** Execute db:load_config 
** Execute db:migrate 
    ActiveRecord::SchemaMigration Load (1.3ms) SELECT "schema_migrations".* FROM "schema_migrations" 
Migrating to AddPasswordDigestToUsers (20150824215943) 
    (1.0ms) BEGIN 
== 20150824215943 AddPasswordDigestToUsers: migrating ========================= 
-- add_column(:users, :password_digest, :string) 
    (1.5ms) ALTER TABLE "users" ADD "password_digest" character varying 
PG::UndefinedTable: ERROR: relation "users" does not exist 
: ALTER TABLE "users" ADD "password_digest" character varying 
    (0.9ms) ROLLBACK 
rake aborted! 
StandardError: An error has occurred, this and all later migrations canceled: 

PG::UndefinedTable: ERROR: relation "users" does not exist 
: ALTER TABLE "users" ADD "password_digest" character varying/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.2/lib/active_record/connection_adapters/postgresql/database_statements.rb:155:in `async_exec' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.2/lib/active_record/connection_adapters/postgresql/database_statements.rb:155:in `block in execute' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract_adapter.rb:473:in `block in log' 
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.2/lib/active_support/notifications/instrumenter.rb:20:in `instrument' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract_adapter.rb:467:in `log' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.2/lib/active_record/connection_adapters/postgresql/database_statements.rb:154:in `execute' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract/schema_statements.rb:393:in `add_column' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.2/lib/active_record/connection_adapters/postgresql/schema_statements.rb:425:in `add_column' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:662:in `block in method_missing' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:632:in `block in say_with_time' 
/app/vendor/ruby-2.0.0/lib/ruby/2.0.0/benchmark.rb:281:in `measure' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:632:in `say_with_time' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:652:in `method_missing' 
/app/db/migrate/20150824215943_add_password_digest_to_users.rb:3:in `change' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:606:in `exec_migration' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:590:in `block (2 levels) in migrate' 
/app/vendor/ruby-2.0.0/lib/ruby/2.0.0/benchmark.rb:281:in `measure' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:589:in `block in migrate' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:292:in `with_connection' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:588:in `migrate' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:765:in `migrate' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:995:in `block in execute_migration_in_transaction' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:1041:in `block in ddl_transaction' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract/transaction.rb:188:in `within_new_transaction' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.2/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.2/lib/active_record/transactions.rb:220:in `transaction' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:1041:in `ddl_transaction' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:994:in `execute_migration_in_transaction' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:956:in `block in migrate' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:952:in `each' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:952:in `migrate' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:820:in `up' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.2/lib/active_record/migration.rb:798:in `migrate' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.2/lib/active_record/tasks/database_tasks.rb:137:in `migrate' 
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.2/lib/active_record/railties/databases.rake:44:in `block (2 levels) in <top (required)>' 
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.4.2/lib/rake/task.rb:240:in `call' 
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.4.2/lib/rake/task.rb:240:in `block in execute' 
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.4.2/lib/rake/task.rb:235:in `each' 
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.4.2/lib/rake/task.rb:235:in `execute' 
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.4.2/lib/rake/task.rb:179:in `block in invoke_with_call_chain' 
/app/vendor/ruby-2.0.0/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize' 
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.4.2/lib/rake/task.rb:172:in `invoke_with_call_chain' 
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.4.2/lib/rake/task.rb:165:in `invoke' 
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:150:in `invoke_task' 
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:106:in `block (2 levels) in top_level' 
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:106:in `each' 
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:106:in `block in top_level' 
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:115:in `run_with_threads' 
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:100:in `top_level' 
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:78:in `block in run' 
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:176:in `standard_exception_handling' 
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:75:in `run' 
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.4.2/bin/rake:33:in `<top (required)>' 
/app/vendor/bundle/ruby/2.0.0/bin/rake:23:in `load' 
/app/vendor/bundle/ruby/2.0.0/bin/rake:23:in `<main>' 

回答

1

得到它的工作。起初尝试heroku pg:reset DATABASE无济于事。 然后运行heroku run rake db:reset,然后成功迁移

相关问题