ruby - When I deploy my rails app to heroku a foreign key disappears -


all code i'm showing below code have cloned heroku.

i have relationship in app:

schema

  create_table "spots", id: false, force: :cascade |t|     t.string  "id",        null: false     t.integer "bid_cents", null: false     t.integer "ask_cents", null: false   end    create_table "products", id: false, force: :cascade |t|     t.string   "id",                                       null: false     t.string   "type",                                     null: false     t.text     "description",                              null: false     t.decimal  "weight",                                   null: false     t.string   "metal",                                    null: false     t.string   "spot_id",                                  null: false     t.integer  "elemetal_capital_premium_cents"     t.integer  "goldtrex_markup_cents",                    null: false     t.datetime "created_at",                               null: false     t.datetime "updated_at",                               null: false     t.integer  "shopify_id",                     limit: 8, null: false   end  add_index "products", ["spot_id"], name: "index_products_on_spot_id", using: :btree 

extract models

extract product

class product < activerecord::base   self.primary_key = :id    belongs_to :spot    before_create :shopify_create   before_update :shopify_update   ... 

extract spot

class spot < activerecord::base   self.primary_key = :id    monetize :bid_cents   monetize :ask_cents    has_many :products 

extract of inheritance product elemetalcapitalproduct , goldtrexproduct

class elemetalcapitalproduct < product    def self.available_products     elemetalcapital::product.all.size   end  class goldtrexproduct < product   validates_presence_of :id,                          :description,                          :weight,                          :metal,                          :spot_id,                         :goldtrex_markup_cents 

methods i'm trying use

def self.update_products!     ec_products = elemetalcapital::product.all     transaction       ec_products.each |ec_product|         product = elemetalcapitalproduct.where(id: ec_product.id).first_or_initialize         product.spot_id = ec_product.spot         product.goldtrex_markup = 25         product.description = ec_product.description         product.metal = ec_product.metal         product.weight = ec_product.weight         product.elemetal_capital_premium = ec_product.premiumbuy         product.save!       end     end 

in controller:

  def master_update     elemetalcapitalproduct.update_products!     redirect_to elemetal_capital_products_path   end 

problem

if run method in local machine works. however, when deploy heroku, , try use method got error:

started "/elemetal_capital_products/elemetal_capital_api_dashboard" 101.176.220.53 @ 2015-07-22 15:11:55 +0000 2015-07-22t15:11:55.383259+00:00 app[web.1]:   user load (2.0ms)  select  "users".* "users" "users"."id" = $1 limit 1  [["id", 1]] 2015-07-22t15:11:55.380497+00:00 app[web.1]: processing elemetalcapitalproductscontroller#elemetal_capital_api_dashboard html 2015-07-22t15:11:55.386042+00:00 app[web.1]:   rendered shared/_page_title.erb (0.1ms) 2015-07-22t15:11:55.900630+00:00 heroku[router]: at=info method=get path="/elemetal_capital_products/elemetal_capital_api_dashboard" host=goldtrex.herokuapp.com request_id=a6b622f6-aa23-4a77-817f-deb3d236b7eb fwd="101.176.220.53" dyno=web.1 connect=0ms service=524ms status=200 bytes=5498 2015-07-22t15:11:55.886397+00:00 app[web.1]:   rendered elemetal_capital_products/elemetal_capital_api_dashboard.html.erb within layouts/application (501.3ms) 2015-07-22t15:11:55.888365+00:00 app[web.1]: completed 200 ok in 508ms (views: 504.2ms | activerecord: 2.0ms) 2015-07-22t15:11:57.753099+00:00 app[web.1]: started post "/elemetal_capital_products/master_update" 101.176.220.53 @ 2015-07-22 15:11:57 +0000 2015-07-22t15:11:57.926609+00:00 app[web.1]:    (1.9ms)  begin 2015-07-22t15:11:57.944657+00:00 app[web.1]:  2015-07-22t15:11:57.942913+00:00 app[web.1]:    (2.0ms)  rollback 2015-07-22t15:11:57.944661+00:00 app[web.1]: nomethoderror (undefined method `spot_id=' #<elemetalcapitalproduct:0x007f00909740b8>): 2015-07-22t15:11:57.944664+00:00 app[web.1]:   app/models/product.rb:95:in `each' 2015-07-22t15:11:57.944663+00:00 app[web.1]:   app/models/product.rb:97:in `block (2 levels) in update_products!' 2015-07-22t15:11:57.944665+00:00 app[web.1]:   app/models/product.rb:95:in `block in update_products!' 2015-07-22t15:11:57.944667+00:00 app[web.1]:   app/models/product.rb:94:in `update_products!' 2015-07-22t15:11:57.944668+00:00 app[web.1]:   app/controllers/elemetal_capital_products_controller.rb:34:in `master_update' 2015-07-22t15:11:57.944670+00:00 app[web.1]:  2015-07-22t15:11:57.944671+00:00 app[web.1]:  2015-07-22t15:11:57.756503+00:00 app[web.1]: processing elemetalcapitalproductscontroller#master_update html 2015-07-22t15:11:57.756599+00:00 app[web.1]:   parameters: {"authenticity_token"=>"r8o+pluofdbhuttieadq1msehoxt0tyzqz/bf6378zl2rdhvmepsyxh7ftpb5p///zsaknwgrlozsin17d94ea=="} 2015-07-22t15:11:57.760060+00:00 app[web.1]:   user load (2.1ms)  select  "users".* "users" "users"."id" = $1 limit 1  [["id", 1]] 2015-07-22t15:11:57.933116+00:00 app[web.1]:   elemetalcapitalproduct load (2.2ms)  select  "products".* "products" "products"."type" in ('elemetalcapitalproduct') , "products"."id" = $1  order "products"."id" asc limit 1  [["id", "sbar10-opm"]] 2015-07-22t15:11:57.943605+00:00 app[web.1]: completed 500 internal server error in 187ms 2015-07-22t15:11:57.951593+00:00 heroku[router]: at=info method=post path="/elemetal_capital_products/master_update" host=goldtrex.herokuapp.com request_id=075d778d-acfb-4438-9f0d-a59b5f409a16 fwd="101.176.220.53" dyno=web.1 connect=1ms service=197ms status=500 bytes=1741 
  • i have run migrations on production app , of them up.

something strange

if have rails console in heroku, , type product see attributes can't see spot_id

product => product(id: string, type: string, description: text, weight: decimal, metal: string, elemetal_capital_premium_cents: integer, goldtrex_markup_cents: integer, created_at: datetime, updated_at: datetime, shopify_id: integer) 

but if go local machine, can see spot_id:

[3] pry(main)> product => product(id: string, type: string, description: text, weight: decimal, metal: string, spot_id: string, elemetal_capital_premium_cents: integer, goldtrex_markup_cents: integer, created_at: datetime, updated_at: datetime, shopify_id: integer) 

could me problem?, compare heroku code master branch, , same. i'm thinking running migration add spot_id, won't make sense because in schema relationship exists, in model apparently doesn't exist.

thank you.

heroku not run migration when deploy code have run migration right after push code:

 heroku run rake db:migrate 

and explain why can't see new column spot_id in product model.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -