Создание пользователя на консоли heroku Руководство по Ruby on Rails от Майкла Хартла

Я новичок, работаю с учебником Ruby on Rails Майкла Хартла. Я пытаюсь создать пользователя в консоли Heroku: WWWq&index=40" rel="nofollow noreferrer">Вот что я следующее: (35:21)

irb(main):001:0> User.create!(:name => "Example User", :email => "[email protected]", :password => "foobar", :password_confirmation => "foobar")

Я получаю эту ошибку! Я не понимаю PGError: ERROR: relation "users" does not exist

PGError: ERROR:  relation "users" does not exist
LINE 5:              WHERE a.attrelid = '"users"'::regclass
                                        ^
:             SELECT a.attname, format_type(a.atttypid, a.atttypmod),
                     pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
              FROM pg_attribute a LEFT JOIN pg_attrdef d
                ON a.attrelid = d.adrelid AND a.attnum = d.adnum
             WHERE a.attrelid = '"users"'::regclass
               AND a.attnum > 0 AND NOT a.attisdropped
             ORDER BY a.attnum

ActiveRecord::StatementInvalid: PGError: ERROR:  relation "users" does not exist
LINE 5:              WHERE a.attrelid = '"users"'::regclass
                                        ^
:             SELECT a.attname, format_type(a.atttypid, a.atttypmod),
                     pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
              FROM pg_attribute a LEFT JOIN pg_attrdef d
                ON a.attrelid = d.adrelid AND a.attnum = d.adnum
             WHERE a.attrelid = '"users"'::regclass
               AND a.attnum > 0 AND NOT a.attisdropped
             ORDER BY a.attnum

    from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/connection_adapters/postgresql_adapter.rb:1161:in `async_exec'
    from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/connection_adapters/postgresql_adapter.rb:1161:in `exec_no_cache'
    from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/connection_adapters/postgresql_adapter.rb:660:in `block in exec_query'
    from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log'
    from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
    from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'
    from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/connection_adapters/postgresql_adapter.rb:659:in `exec_query'
    from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/connection_adapters/postgresql_adapter.rb:1286:in `column_definitions'
    from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/connection_adapters/postgresql_adapter.rb:855:in `columns'
    from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/connection_adapters/schema_cache.rb:12:in `block in initialize'
    from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/model_schema.rb:228:in `yield'
    from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/model_schema.rb:228:in `default'
    from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/model_schema.rb:228:in `columns'
    from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/model_schema.rb:243:in `column_defaults'
    from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/base.rb:482:in `initialize'
    from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/validations.rb:39:in `new'
    from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/validations.rb:39:in `create!'
    from (irb):1
    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/commands/console.rb:47:in `start'
    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/commands/console.rb:8:in `start'
    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/commands.rb:41:in `<top (required)>'
    from script/rails:6:in `require'

person JamesBoy90    schedule 24.06.2013    source источник


Ответы (2)


Предполагая, что у вас есть миграции, запустите следующее

heroku run rake db:migrate

person Luís Ramalho    schedule 24.06.2013

Кажется, что ваша таблица users отсутствует. Вы запускали rake db:migrate в рабочей среде? Я не очень хорошо знаком с Heroku, но обычно вы можете запустить его как

rake db:migrate RAILS_ENV=production 
person sameera207    schedule 24.06.2013