简体   繁体   中英

Trouble deploying to Heroku

Hi I have been trying to deploy my ruby on rails application to Heroku for the past few days and I get this error "We're sorry, but something went wrong. We've been notified about this issue and we'll take a look at it shortly". Even though I have followed the Heroku guide I check the Heroku logs and this is what it says:

2012-03-05T18:59:41+00:00 app[web.1]:   Processing by StoreController#index as HTML
2012-03-05T18:59:41+00:00 app[web.1]: Rendered store/index.html.erb within    layouts/application (66.7ms)
2012-03-05T18:59:41+00:00 app[web.1]: Completed 500 Internal Server Error in 164ms
2012-03-05T18:59:41+00:00 app[web.1]: 
2012-03-05T18:59:41+00:00 app[web.1]: ActionView::Template::Error (PG::Error: ERROR:  column "name" does not exist
2012-03-05T18:59:41+00:00 app[web.1]: LINE 1: SELECT "products".* FROM "products"  ORDER BY Name
2012-03-05T18:59:41+00:00 app[web.1]:                                                       ^
2012-03-05T18:59:41+00:00 app[web.1]: : SELECT "products".* FROM "products"  ORDER BY Name):
2012-03-05T18:59:41+00:00 app[web.1]:     2: <p id= "notice"><%= notice %></p>
2012-03-05T18:59:41+00:00 app[web.1]:     3: <% end %>
2012-03-05T18:59:41+00:00 app[web.1]:     8:        
2012-03-05T18:59:41+00:00 app[web.1]:     6:    <div class ="entry">
2012-03-05T18:59:41+00:00 app[web.1]:   app/views/store/index.html.erb:5:in `_app_views_store_index_html_erb___635623125359494649_35532040'
2012-03-05T18:59:41+00:00 app[web.1]:     7:        <div class="img">
2012-03-05T18:59:41+00:00 app[web.1]:     5: <% @products.each do |product| %>
2012-03-05T18:59:41+00:00 app[web.1]: 
2012-03-05T18:59:41+00:00 app[web.1]:     4: 
2012-03-05T18:59:41+00:00 app[web.1]: 
2012-03-05T18:59:41+00:00 app[web.1]: cache: [GET /] miss

What could be the issue as it works fine locally? Could it be the fact I'm using SQLite3 as my database for test and developement but for Heroku it uses PostgreSQL?

Let us look closely at your error:

ActionView::Template::Error (PG::Error: ERROR:  column "name" does not exist
LINE 1: SELECT "products".* FROM "products"  ORDER BY Name
                                                      ^

The upper case but unquoted Name is very suspicious; SQL identifiers are case-insensitive unless you quote them (they're supposed to be normalized to upper case but PostgreSQL normalizes to lower case). So, these tables are all the same:

create table t (name varchar(255));
create table t (Name varchar(255));
create table t (nAmE varchar(255));
create table t (NAME varchar(255));

but these are all different:

create table t ("name" varchar(255));
create table t ("Name" varchar(255));
create table t ("nAmE" varchar(255));
create table t ("NAME" varchar(255));

I would guess that you have created your table with a "Name" column rather than a name column. I'd recommend recreating your table with a lower case name column; alternatively, you could quote the column when you call order :

Model.where(...).order('"Name"')

But really, using lower case column names will make your life easier and the people that maintain your code will have fonder memories of you.

You note in comments elsewhere that you're developing on SQLite but deploying to PostgreSQL. SQLite seems to ignore case in column names even when they're quoted:

sqlite> create table t ("Name" text);
sqlite> insert into t values ('a');
sqlite> select * from t order by name;
Name
a

So everything would work fine in SQLite. PostgreSQL, however, pays attention to the case of quoted identifiers (as the SQL spec says it should) so ORDER BY Name will fail if the column was quoted when it was created (ie something like create table t ("Name" varchar... ).

There are other differences between SQLite and PostgreSQL. ActiveRecord cannot protect you from all the differences between databases so you should always develop, test, and deploy using the same stack (all the way down to the database version).

看起来您可能需要迁移。

heroku run rake db:migrate
  • is your git status clean?
  • If so, have you git push heroku master lately?

Make sure your code is committed and pushed. Then you'll want to run the migrations.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM