Ruby on rails PG::UndefinedTable:错误:关系“…”不存在

Ruby on rails PG::UndefinedTable:错误:关系“…”不存在,ruby-on-rails,ruby,heroku,Ruby On Rails,Ruby,Heroku,我知道这已经被问过很多次了,但我尝试过很多解决方案,但都没有成功。我在Heroku上部署了一个Rails应用程序,它在本地运行,但我知道我们很抱歉,但出了问题。当我尝试在Heroku上启动它时 我试过了 heroku run rake db:migrate heroku restart heroku open 但该表已存在于架构中 我试过: rake db:reset 及 rake db:drop db:create db:migrate 我知道默认情况下,更改是在开发环境中完成的,这可能

我知道这已经被问过很多次了,但我尝试过很多解决方案,但都没有成功。我在Heroku上部署了一个Rails应用程序,它在本地运行,但我知道我们很抱歉,但出了问题。当我尝试在Heroku上启动它时

我试过了

heroku run rake db:migrate
heroku restart
heroku open 
但该表已存在于架构中

我试过:

rake db:reset
及 rake db:drop db:create db:migrate

我知道默认情况下,更改是在开发环境中完成的,这可能是原因吗?我正在开发环境中运行更改,但是“heroku open”打开了产品环境

更新,heroku日志的完整代码段: heroku原木

    2015-12-12T05:47:57.814680+00:00 app[web.1]:    /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/server.rb:32:in `start'
2015-12-12T05:47:57.814679+00:00 app[web.1]:    /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/server.rb:170:in `block in start'
2015-12-12T05:47:57.814682+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/server.rb:264:in `start'
2015-12-12T05:47:57.814680+00:00 app[web.1]:    /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/server.rb:160:in `start'
2015-12-12T05:47:57.814683+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.6/lib/rails/commands/server.rb:69:in `start'
2015-12-12T05:47:57.814681+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/handler/webrick.rb:14:in `run'
2015-12-12T05:47:57.814684+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.6/lib/rails/commands/commands_tasks.rb:81:in `block in server'
2015-12-12T05:47:57.814685+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.6/lib/rails/commands/commands_tasks.rb:76:in `tap'
2015-12-12T05:47:57.814686+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.6/lib/rails/commands/commands_tasks.rb:76:in `server'
2015-12-12T05:47:57.814686+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.6/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
2015-12-12T05:47:57.814687+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/railties-4.1.6/lib/rails/commands.rb:17:in `<top (required)>'
2015-12-12T05:47:57.814688+00:00 app[web.1]:    bin/rails:8:in `require'
2015-12-12T05:47:57.814688+00:00 app[web.1]:    bin/rails:8:in `<main>'
2015-12-12T05:47:57.814711+00:00 app[web.1]: [2015-12-12 05:47:57] INFO  going to shutdown ...
2015-12-12T05:47:57.814800+00:00 app[web.1]: Exiting
2015-12-12T05:47:57.814767+00:00 app[web.1]: [2015-12-12 05:47:57] INFO  WEBrick::HTTPServer#start done.
2015-12-12T05:47:58.668656+00:00 heroku[web.1]: Process exited with status 143
2015-12-12T15:25:42.166048+00:00 heroku[web.1]: Unidling
2015-12-12T15:25:42.166363+00:00 heroku[web.1]: State changed from down to starting
2015-12-12T15:25:43.961413+00:00 heroku[web.1]: Starting process with command `bin/rails server -p 31053 -e production`
2015-12-12T15:25:47.675210+00:00 app[web.1]: [2015-12-12 15:25:47] INFO  WEBrick 1.3.1
2015-12-12T15:25:47.675235+00:00 app[web.1]: [2015-12-12 15:25:47] INFO  ruby 2.0.0 (2014-11-13) [x86_64-linux]
2015-12-12T15:25:47.675544+00:00 app[web.1]: [2015-12-12 15:25:47] INFO  WEBrick::HTTPServer#start: pid=3 port=31053
2015-12-12T15:25:48.347999+00:00 heroku[web.1]: State changed from starting to up
2015-12-12T15:25:49.238228+00:00 app[web.1]: => Booting WEBrick
2015-12-12T15:25:49.238232+00:00 app[web.1]: => Rails 4.1.6 application starting in production on http://0.0.0.0:31053
2015-12-12T15:25:49.238233+00:00 app[web.1]: => Run `rails server -h` for more startup options
2015-12-12T15:25:49.238235+00:00 app[web.1]: => Notice: server is listening on all interfaces (0.0.0.0). Consider using 127.0.0.1 (--binding option)
2015-12-12T15:25:49.238235+00:00 app[web.1]: => Ctrl-C to shutdown server
2015-12-12T15:25:49.238236+00:00 app[web.1]: Started GET "/" for 98.196.181.134 at 2015-12-12 15:25:49 +0000
2015-12-12T15:25:49.371270+00:00 app[web.1]: Processing by UsersController#index as HTML
2015-12-12T15:25:49.385278+00:00 heroku[router]: at=info method=GET path="/" host=appname.herokuapp.com request_id=276e00fc-cadd-4b08-ac52-6d72099c9c2e fwd="98.196.181.134" dyno=web.1 connect=1ms service=156ms status=500 bytes=1754
2015-12-12T15:25:49.384220+00:00 app[web.1]: LINE 1: SELECT "users".* FROM "users"
2015-12-12T15:25:49.384216+00:00 app[web.1]: PG::UndefinedTable: ERROR:  relation "users" does not exist
2015-12-12T15:25:49.384221+00:00 app[web.1]:                                   ^
2015-12-12T15:25:49.384222+00:00 app[web.1]: : SELECT "users".* FROM "users"
2015-12-12T15:25:49.384742+00:00 app[web.1]:   Rendered users/index.html.erb within layouts/application (3.7ms)
2015-12-12T15:25:49.384868+00:00 app[web.1]: Completed 500 Internal Server Error in 14ms
2015-12-12T15:25:49.387101+00:00 app[web.1]: 
2015-12-12T15:25:49.387105+00:00 app[web.1]: LINE 1: SELECT "users".* FROM "users"
2015-12-12T15:25:49.387103+00:00 app[web.1]: ActionView::Template::Error (PG::UndefinedTable: ERROR:  relation "users" does not exist
2015-12-12T15:25:49.387105+00:00 app[web.1]:                                   ^
2015-12-12T15:25:49.387106+00:00 app[web.1]: : SELECT "users".* FROM "users"):
2015-12-12T15:25:49.387107+00:00 app[web.1]:     15: 
2015-12-12T15:25:49.387107+00:00 app[web.1]:     14:   </thead>
2015-12-12T15:25:49.387110+00:00 app[web.1]:     17:     <% @users.each do |user| %>
2015-12-12T15:25:49.387110+00:00 app[web.1]:     18:       <tr>
2015-12-12T15:25:49.387108+00:00 app[web.1]:     16:   <tbody>
2015-12-12T15:25:49.387112+00:00 app[web.1]:     20:         <td><%= user.address %></td>
2015-12-12T15:25:49.387111+00:00 app[web.1]:     19:         <td><%= user.name %></td>
2015-12-12T15:25:49.387116+00:00 app[web.1]:   app/views/users/index.html.erb:17:in `_app_views_users_index_html_erb___3405507757113956440_70276178207640'
2015-12-12T15:25:49.387118+00:00 app[web.1]: 
2015-12-12T15:25:49.387117+00:00 app[web.1]: 
2015-12-12T15:27:59.501112+00:00 heroku[router]: at=info method=GET path="/" host=appname.herokuapp.com request_id=279ab493-5a01-4b89-b0a8-cbc9cb51fe83 fwd="98.196.181.134" dyno=web.1 connect=0ms service=18ms status=500 bytes=1754
2015-12-12T15:27:59.486906+00:00 app[web.1]: Started GET "/" for 98.196.181.134 at 2015-12-12 15:27:59 +0000
2015-12-12T15:27:59.496321+00:00 app[web.1]: LINE 1: SELECT "users".* FROM "users"
2015-12-12T15:27:59.496322+00:00 app[web.1]:                                   ^
2015-12-12T15:27:59.496318+00:00 app[web.1]: PG::UndefinedTable: ERROR:  relation "users" does not exist
2015-12-12T15:27:59.496323+00:00 app[web.1]: : SELECT "users".* FROM "users"
2015-12-12T15:27:59.499226+00:00 app[web.1]: 
2015-12-12T15:27:59.496875+00:00 app[web.1]:   Rendered users/index.html.erb within layouts/application (2.7ms)
2015-12-12T15:27:59.496993+00:00 app[web.1]: Completed 500 Internal Server Error in 4ms
2015-12-12T15:27:59.499229+00:00 app[web.1]: ActionView::Template::Error (PG::UndefinedTable: ERROR:  relation "users" does not exist
2015-12-12T15:27:59.499231+00:00 app[web.1]:                                   ^
2015-12-12T15:27:59.499230+00:00 app[web.1]: LINE 1: SELECT "users".* FROM "users"
2015-12-12T15:27:59.499231+00:00 app[web.1]: : SELECT "users".* FROM "users"):
2015-12-12T15:27:59.499233+00:00 app[web.1]:     16:   <tbody>
2015-12-12T15:27:59.499232+00:00 app[web.1]:     14:   </thead>
2015-12-12T15:27:59.499233+00:00 app[web.1]:     15: 
2015-12-12T15:27:59.499234+00:00 app[web.1]:     17:     <% @users.each do |user| %>
2015-12-12T15:27:59.499235+00:00 app[web.1]:     18:       <tr>
2015-12-12T15:27:59.499239+00:00 app[web.1]: 
2015-12-12T15:27:59.499237+00:00 app[web.1]:     20:         <td><%= user.address %></td>
2015-12-12T15:27:59.499236+00:00 app[web.1]:     19:         <td><%= user.name %></td>
2015-12-12T15:27:59.499239+00:00 app[web.1]:   app/views/users/index.html.erb:17:in `_app_views_users_index_html_erb___3405507757113956440_70276178207640'
2015-12-12T15:27:59.499240+00:00 app[web.1]: 
2015-12-12T15:27:59.493196+00:00 app[web.1]: Processing by UsersController#index as HTML
2015-12-12T15:28:02.359919+00:00 app[web.1]: Started GET "/" for 98.196.181.134 at 2015-12-12 15:28:02 +0000
2015-12-12T15:28:02.366634+00:00 app[web.1]: PG::UndefinedTable: ERROR:  relation "users" does not exist
2015-12-12T15:28:02.366638+00:00 app[web.1]:                                   ^
2015-12-12T15:28:02.366639+00:00 app[web.1]: : SELECT "users".* FROM "users"
2015-12-12T15:28:02.366637+00:00 app[web.1]: LINE 1: SELECT "users".* FROM "users"
2015-12-12T15:28:02.367435+00:00 app[web.1]:   Rendered users/index.html.erb within layouts/application (3.1ms)
2015-12-12T15:28:02.367587+00:00 app[web.1]: Completed 500 Internal Server Error in 4ms
2015-12-12T15:28:02.369955+00:00 app[web.1]: 
2015-12-12T15:28:02.369959+00:00 app[web.1]: LINE 1: SELECT "users".* FROM "users"
2015-12-12T15:28:02.370984+00:00 heroku[router]: at=info method=GET path="/" host=appname.herokuapp.com request_id=2b1fbddf-0ef7-4d8c-9107-9e67a2a1ca6a fwd="98.196.181.134" dyno=web.1 connect=0ms service=14ms status=500 bytes=1754
2015-12-12T15:28:02.369958+00:00 app[web.1]: ActionView::Template::Error (PG::UndefinedTable: ERROR:  relation "users" does not exist
2015-12-12T15:28:02.363203+00:00 app[web.1]: Processing by UsersController#index as HTML
2015-12-12T15:28:02.369960+00:00 app[web.1]:                                   ^
2015-12-12T15:28:02.369960+00:00 app[web.1]: : SELECT "users".* FROM "users"):
2015-12-12T15:28:02.369961+00:00 app[web.1]:     14:   </thead>
2015-12-12T15:28:02.369962+00:00 app[web.1]:     15: 
2015-12-12T15:28:02.369963+00:00 app[web.1]:     17:     <% @users.each do |user| %>
2015-12-12T15:28:02.369964+00:00 app[web.1]:     18:       <tr>
2015-12-12T15:28:02.369962+00:00 app[web.1]:     16:   <tbody>
2015-12-12T15:28:02.369964+00:00 app[web.1]:     19:         <td><%= user.name %></td>
2015-12-12T15:28:02.369965+00:00 app[web.1]:     20:         <td><%= user.address %></td>
2015-12-12T15:28:02.369966+00:00 app[web.1]:   app/views/users/index.html.erb:17:in `_app_views_users_index_html_erb___3405507757113956440_70276178207640'
2015-12-12T15:28:02.369967+00:00 app[web.1]: 
2015-12-12T15:28:02.369967+00:00 app[web.1]:
如您所见,没有创建表用户。此外,模式_迁移也是空的


我错过了什么?为什么不在prod env中创建表用户

看起来您在Heroku上运行的迁移实际上并没有创建表。您可以通过运行heroku运行rails c进行检查,然后尝试ActiveRecord::Base.connection.tables列出您的表


有时PG对迁移的影响与Sqlite3/MySQL不同。建议在本地开发人员上运行PG以镜像迁移并在部署前解决问题

您需要从Heroku日志中添加更多代码段。请尝试在应用程序中设置一个不使用数据库连接的端点,并查看它是否有效。以防它起作用。然后是生产环境中的迁移问题。您可以通过启用“在生产环境中临时显示错误@SunnyK Done”来确保@Ashutshagrawal我更改了文件,结果:ActiveRecord::Statement在Usersindex中无效显示/app/app/views/users/index.html.erb,其中第17行出现:PG::UndefinedTable:错误:关系用户不存在第1行:选择用户。*来自用户^:选择用户。*来自用户这与此非常类似,但解决方案对我不起作用,我尝试迁移数据库,然后推送,反之亦然!你解决了你的问题吗?不幸的是,我最终删除了所有内容并重新开始,不知道为什么它一开始就不起作用。谢谢你的反馈。您是对的,没有创建表。我尝试了:heroku pg:psql然后\d列出可用的数据库,我得到了一个表,那就是schema_迁移,运行select*from schema_migrations;,它以零行返回。我知道如何通过打开服务器然后访问localhost:3000在本地运行应用程序,如何在本地开发人员上运行PG?请查看页面以设置PG。如果您使用的是Ubuntu:。在机器上安装PG往往需要更多的动手操作。因此,请遵循指南来帮助您进行设置
$ rake db:schema:load RAILS_ENV=production --trace
** Invoke db:schema:load (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:schema:load
-- enable_extension("plpgsql")
   -> 0.1872s
-- create_table("users", {:force=>true})
   -> 0.1565s
-- initialize_schema_migrations_table()
   -> 0.0876s
$ heroku restart
Restarting dynos... done
$ heroku open
Opening appname... done
$ heroku pg:psql
---> Connecting to HEROKU_POSTGRESQL_WHITE_URL (DATABASE_URL)
psql (9.4.5, server 9.3.9)

appname::WHITE=> \d
                  List of relations
 Schema |       Name        | Type  |     Owner      
--------+-------------------+-------+----------------
 public | schema_migrations | table | ownername
(1 row)

$ heroku run rails c
Running rails c on appname... up, run.1689
Loading production environment (Rails 4.1.6)
irb(main):001:0> ActiveRecord::Base.connection.tables
=> ["schema_migrations"]
irb(main):002:0>