Ruby on rails 购物车/签出ActiveRecord::InvalidForeignKey(PG::ForeignKeyViolation:Heroku上的错误,但不是Localhost上的错误

Ruby on rails 购物车/签出ActiveRecord::InvalidForeignKey(PG::ForeignKeyViolation:Heroku上的错误,但不是Localhost上的错误,ruby-on-rails,heroku,Ruby On Rails,Heroku,在我的应用程序上有一个可用的购物车/结帐功能,它在本地主机上运行得非常好,但是当我部署到Heroku时,当单击“添加到购物车”按钮时,不会将项目添加到购物车 Heroku日志显示了以下错误: 2017-05-19T21:12:00.506230+00:00 app[web.1]: Started POST "/order_items" for 68.225.227.137 at 2017-05-19 21:12:00 +0000 2017-05-19T21:12:00.508991+00:00

在我的应用程序上有一个可用的购物车/结帐功能,它在本地主机上运行得非常好,但是当我部署到Heroku时,当单击“添加到购物车”按钮时,不会将项目添加到购物车

Heroku日志显示了以下错误:

2017-05-19T21:12:00.506230+00:00 app[web.1]: Started POST "/order_items" for 68.225.227.137 at 2017-05-19 21:12:00 +0000
2017-05-19T21:12:00.508991+00:00 app[web.1]: Processing by OrderItemsController#create as JS
2017-05-19T21:12:00.511223+00:00 app[web.1]: User Load (0.8ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT 1 [["id", 1]]
2017-05-19T21:12:00.509041+00:00 app[web.1]: Parameters: {"utf8"=>"✓", "order_item"=>{"quantity"=>"1", "product_id"=>"2"}, "commit"=>"Add to Cart"}
2017-05-19T21:12:00.516450+00:00 app[web.1]: Product Load (0.7ms) SELECT "products".* FROM "products" WHERE "products"."active" = $1 AND "products"."id" = $2 LIMIT 1 [["active", "t"], ["id", 2]]
2017-05-19T21:12:00.513630+00:00 app[web.1]: (0.6ms) BEGIN
2017-05-19T21:12:00.531537+00:00 app[web.1]: SQL (12.8ms) INSERT INTO "orders" ("user_id", "subtotal", "created_at", "updated_at", "order_status_id") VALUES ($1, $2, $3, $4, $5) RETURNING "id" [["user_id", 1], ["subtotal", "499.0"], ["created_at", "2017-05-19 21:12:00.517193"], ["updated_at", "2017-05-19 21:12:00.517193"], ["order_status_id", 1]]
2017-05-19T21:12:00.532478+00:00 app[web.1]: (0.8ms) ROLLBACK
2017-05-19T21:12:00.533488+00:00 app[web.1]: 
2017-05-19T21:12:00.532671+00:00 app[web.1]: Completed 500 Internal Server Error in 24ms (ActiveRecord: 15.8ms)
2017-05-19T21:12:00.533491+00:00 app[web.1]: DETAIL: Key (order_status_id)=(1) is not present in table "order_statuses".
2017-05-19T21:12:00.533490+00:00 app[web.1]: ActiveRecord::InvalidForeignKey (PG::ForeignKeyViolation: ERROR: insert or update on table "orders" violates foreign key constraint "fk_rails_7a22cf8b0e"
2017-05-19T21:12:00.533492+00:00 app[web.1]: : INSERT INTO "orders" ("user_id", "subtotal", "created_at", "updated_at", "order_status_id") VALUES ($1, $2, $3, $4, $5) RETURNING "id"):
2017-05-19T21:12:00.533493+00:00 app[web.1]: app/controllers/order_items_controller.rb:7:in `create'
2017-05-19T21:12:00.533494+00:00 app[web.1]: 
2017-05-19T21:12:00.533495+00:00 app[web.1]: 
2017-05-19T21:12:06.465383+00:00 heroku[router]: at=info method=POST path="/order_items" host=aloop-offroad.herokuapp.com request_id=b13e7b04-7ac0-44fe-b58f-a850ce4cd7e8 fwd="68.225.227.137" dyno=web.1 connect=0ms service=16ms status=500 bytes=1754 protocol=http

有人能看到发生了什么吗?我迷路了,因为我看不到任何可以在
localhost
上工作的东西,但看不到
Heroku

,简而言之,你的错误是,你试图在
orders
中插入一条违反约束的
order\u status\u id
值的记录。这可能是因为你看到了使用一些
OrderStatus
对象在本地编辑数据库,并将其ID硬编码到代码中。但是,这些记录在生产数据库中不存在。您可能应该更新代码,以便根据请求从数据库中提取订单状态选项,然后在生产数据库中创建相关的状态记录

啊哈!谢谢你!我快疯了!