PG :: UndefinedTable:错误:关系“...”不存在

编程入门 行业动态 更新时间:2024-10-25 04:14:15
本文介绍了PG :: UndefinedTable:错误:关系“...”不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

我试过了

heroku run rake db:migrate heroku重启 heroku开启

但该表已存在于模式中

我试过:

rake db:reset

我知道,默认情况下,更改是在开发环境中完成的,这是否是原因?我正在运行开发env中的更改,但'heroku open'打开prod env? heroku日志

更新是heroku日志的完整摘要: pre> 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:在`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:在`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 :在'跑'中 2015-12-12T05:47:57.814684 + 00:00 app [web.1]:/ app / vendor / bundle / r uby / 2.0.0 / gems / railties-4.1.6 / lib / rails / commands / commands_tasks.rb:81:在`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:在`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:在< top(required)>' 2015-12-12T05:47:57.814688 + 00:00 app [web.1]:bin / rails:8:在`require' 2015-12-12T05:47:57.814688 + 00:00 app [web.1]:bin / rails:8:in<<主要>' 2015-12-12T05:47:57.814711 + 00:00应用[web.1]:[2015-12-12 05:47:57]信息将关闭... 2015 - 12-12T05:47:57.814800 + 00:00 app [web.1]:退出 2015-12-12T05:47:57.814767 + 00:00 app [web.1]:[2015-12-12 05 :47:57] INFO WEBrick :: HTTPServer#开始完成。 2015-12-12T05:47:58.668656 + 00:00 heroku [web.1]:进程退出,状态为143 2015-12-12T15:25:42.166048 + 00:00 heroku [web。 1]:Unidling 2015-12-12T15:25:42.166363 + 00:00 heroku [web.1]:状态由下变为开始 2015-12-12T15:25:43.961413 + 00: 00 heroku [web.1]:用命令`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]:状态从开始改为 2015-12-12T15:25:49.238228 + 00:00 app [web.1]:=>启动WEBrick 2015-12-12T15:25:49.238232 + 00:00 app [web.1]:=> Rails 4.1.6应用程序在0.0.0.0:31053上生产开始 2015-12-12T15:25:49.238233 + 00:00 app [web.1]:=>为更多启动选项运行`rails server -h` 2015-12-12T15:25:49.238235 + 00:00 app [web.1]:=>注意:服务器正在监听所有接口(0.0.0.0)。考虑使用127.0.0.1( - 绑定选项) 2015-12-12T15:25:49.238235 + 00:00 app [web.1]:=> Ctrl-C关闭服务器 2015-12-12T15:25:49.238236 + 00:00应用[web.1]:开始GET/为98.196.181.134于2015-12-12 15:25:49 +0000 2015-12-12T15:25:49.371270 + 00:00 app [web.1]:通过UsersController处理#index为HTML 2015-12-12T15:25:49.385278 + 00:00 heroku [router]:at = info method = GET path =/host = appname.herokuapp request_id = 276e00fc-cadd-4b08-ac52-6d72099c9c2e fwd =98.196.181.134dyno = web.1 connect = 1ms service = 156ms status = 500 bytes = 1754 2015-12-12T15:25:49.384220 + 00:00 app [web.1]:LINE 1:SELECTusers。* FROMusers 2015 -12-12T15:25:49.384216 + 00:00 app [web.1]:PG :: UndefinedTable:ERROR:关系用户不存在 2015-12-12T15:25:49.384221 + 00:00 app [web.1]:^ 2015-12-12T15:25:49.384222 + 00:00 app [web.1]::SELECTusers。* FROMusers 2015-12 -12T15:25:49.384742 + 00:00 app [web.1]:在布局/应用程序中呈现用户/ index.html.erb(3.7ms) 2015-12-12T15:25:49.384868 + 00:00应用[网络。 1]:在14ms内完成500次内部服务器错误 2015-12-12T15:25:49.387101 + 00:00应用[web.1]: 2015-12-12T15:25:49.387105 + 00: 00 app [web.1]:LINE 1:SELECTusers。* FROMusers 2015-12-12T15:25:49.387103 + 00:00 app [web.1]:ActionView :: Template: :错误(PG :: UndefinedTable:错误:关系用户不存在 2015-12-12T15:25:49.387105 + 00:00应用[web.1]:^ 2015-12- 12T15:25:49.387106 + 00:00 app [web.1]::SELECTusers。* FROMusers): 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 | %GT; 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应用[web.1]: 2015-12-12T15:25:49.387117 + 00:00应用[web.1]: 2015-12-12T15: 27:59.501112 + 00:00 heroku [router]:at = info method = GET path =/host = appname.herokuapp request_id = 279ab493-5a01-4b89-b0a8-cbc9cb51fe83 fwd =98.196.181.134dyno = web.1 connect = 0ms service = 18ms status = 500 bytes = 1754 2015-12-12T15:27:59.486906 + 00:00 app [web.1]:2015年98.196.181.134开始GET/ -12-12 15:27:59 +0000 2015-12-12T15:27:59.496321 + 00:00 app [web.1]:LINE 1:SELECTusers。* FROMusers 2015-12-12T15:27:59.496322 + 00:00 app [web.1]:^ 2015-12-12T15:27:59.496318 + 00:00 app [web.1]:PG :: UndefinedTable:错误:关系users不存在 2015-12-12T15:27:59.496323 + 00:00 app [web.1]::SELECTusers。* FROMusers 2015-12-12T15:2 7:59.499226 + 00:00 app [web.1]: 2015-12-12T15:27:59.496875 + 00:00 app [web.1]:在布局/应用程序中呈现用户/ index.html.erb (2.7ms) 2015-12-12T15:27:59.496993 + 00:00应用[web.1]:在4ms内完成500次内部服务器错误 2015-12-12T15:27:59.499229 + 00 :00 app [web.1]:ActionView :: Template :: Error(PG :: UndefinedTable:ERROR:relationusersdoes not exist 2015-12-12T15:27:59.499231 + 00:00 app [网络1]:^ 2015-12-12T15:27:59.499230 + 00:00 app [web.1]:LINE 1:SELECTusers。* FROMusers 2015-12 -12T15:27:59.499231 + 00:00 app [web.1]::SELECTusers。* FROMusers): 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 | %GT; 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]:通过UsersController#index处理为HTML 2015-12-12T15:28:02.359919 + 00:00 app [web.1]:2015-12-12 15:28:02 +0000 2015-12开始GET/为98.196.181.134 -12T15:28:02.366634 + 00:00 app [web.1]:PG :: UndefinedTable:ERROR:关系users不存在 2015-12-12T15:28:02.366638 + 00:00 app [网页1]:^ 2015-12-12T15:28:02.366639 + 00:00 app [web.1]::SELECTusers。* FROMusers 2015-12-12T15 :28:02.366637 + 00:00 app [web.1]:LINE 1:SELECTusers。* FROMusers 2015-12-12T15:28:02.367435 + 00:00 app [web.1 ]:在布局/应用程序(3.1ms)内呈现用户/ index.html.erb 2015-12-12T15:28:02.367587 + 00:00应用[web.1]:完成500次内部服务器错误b $ b 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用户。* FROMusers 2015-12-12T15:28:02.370984 + 00:00 heroku [router]:at = info method = GET path =/host = appname.herokuapp request_id = 2b1fbddf-0ef7-4d8c-9107-9e67a2a1ca6a fwd =98.196.181.134dyno = 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:relationusersdoes not exist 2015-12-12T15:28:02.363203 + 00:00 app [web。 1]:UsersController#index处理为HTML 2015-12-12T15:28:02.369960 + 00:00应用[web.1]:^ 2015-12-12T15:28:02.369960 + 00 :00 app [web.1]::SELECTusers。* FROMusers): 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 | %GT; 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]:

更新:根据@ Vincent的回答,我可以判断迁移时Heroku并未创建表,所以我尝试从模式加载数据库.rb,因为我的模式有表,

$ rake db:schema:load RAILS_ENV = production --trace **调用db:schema:load(first_time) **调用环境(first_time) **执行环境 **调用db:load_config(first_time) **执行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重新启动重新启动dynos ...完成 $ heroku开启开启appname ...完成 $ heroku pg:psql - - >连接到HEROKU_POSTGRESQL_WHITE_URL(DATABASE_URL) psql(9.4.5,服务器9.3.9) appname :: WHITE => \d 关系列表 Schema |名称|类型|所有者 -------- + ------------------- + ------- + -------- -------- public | schema_migrations |表| | ownername (1 row) $ heroku run rails c 在appname上运行rails c ...运行.1689 加载生产环境(Rails 4.1。 6) irb(main):001:0> ActiveRecord :: Base.connection.tables => [schema_migrations] irb(main):002:0>

正如您所看到的,表用户并未创建。另外,schema_migrations是空的。

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

解决方案

看起来您在Heroku上运行的迁移实际上并未创建表。您可以通过运行 heroku run rails c 并尝试 ActiveRecord :: Base.connection.tables 来列出您的表格

与Sqlite3 / MySQL相比,PG对迁移有不同的影响。建议在本地开发中运行PG来镜像迁移并在部署之前解决问题

I know this has been asked so many times but I have tried many solutions with no luck. I have a Rails app deployed on Heroku, it works locally but I get "We're sorry, but something went wrong." when I try to launch it on Heroku.

I have tried

heroku run rake db:migrate heroku restart heroku open

but the table already exists in schema

I have tried:

rake db:reset

and rake db:drop db:create db:migrate

I know that by default, changes are done in the development environment, could this be the reason? I'm running the changes in the development env but the 'heroku open' opens the prod env?

Update, the complete snippet for heroku logs: heroku logs

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 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 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 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 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]:

Update: Following on @Vincent's answer, I can tell that the table is not being created on Heroku upon migration, so I tried loading the db from schema.rb since my schema has the table,

$ 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>

As you can see, the table users wasn't created. Also, schema_migrations is empty.

What am I missing? Why is not the table users being created in the prod env?

解决方案

It looks like your migrations that you ran on Heroku didn't actually create the table. You can check by running heroku run rails c and try ActiveRecord::Base.connection.tables to list your tables

Sometimes PG will have different effects to migration compared to Sqlite3/MySQL. It is recommended to run PG on local dev to mirror the migration and solve the problem before deployment

更多推荐

PG :: UndefinedTable:错误:关系“...”不存在

本文发布于:2023-10-14 11:54:22,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不存在   错误   关系   PG   UndefinedTable

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!