ruby on rails - Heroku PG::UndefinedColumn: ERROR does not exist -


this runs fine on rails server doesn't work on heroku , says went wrong etc. happens when search b_pages via bpage_name:

schema:

create_table "b_pages", force: :cascade |t|     t.string   "bpage_name"     t.string   "first_post"     t.datetime "created_at",               null: false     t.datetime "updated_at",               null: false     t.string   "profile_img_file_name"     t.string   "profile_img_content_type"     t.integer  "profile_img_file_size"     t.datetime "profile_img_updated_at"     t.string   "banner_img_file_name"     t.string   "banner_img_content_type"     t.integer  "banner_img_file_size"     t.datetime "banner_img_updated_at"     t.integer  "user_id"     t.string   "status"     t.text     "bio"     t.string   "relationship"     t.text     "whitelist"     t.text     "blacklist" end 

b_page.rb:

def self.search(query)     where("bpage_name ?", "%#{query.downcase}%")  end 

identifiers (such table , column names) case insensitive in sql. however, if double quote them when create table case sensitive. standard sql folds unquoted identifiers upper case postgresql folds them lower case, hence complain bpage_name being unknown column when say:

where("bpage_name ?", "%#{query.downcase}%") 

activerecord double quotes identifiers when creates tables if have column names case sensitive (such bpage_name) have double quote them everywhere use them in sql snippets:

where('"bpage_name" ?', "%#{query.downcase}%") # -----^----------^ 

the recommended practice postgresql (and rails/activerecord matter) use lower case column names underscores separate words. saying this:

t.string   "bpage_name" 

in migration more consistent both conventions , avoid quoting problem completely.

when like:

where(:bpage_name => 'pancakes') 

activerecord add quotes , send:

where "bpage_name" = 'pancakes' 

to database. quoting , case sensitivity issue arises when use bits of sql; of course, end using sql snippets activerecord naming convention still important if don't want litter code bunch of noisy double quotes.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -