ActiveRecord::StatementInvalid: PG::NumericValueOutOfRange: ERROR: value "150000200000" is out of range for type integer

ActiveRecord::StatementInvalid: PG::NumericValueOutOfRange: ERROR: value "150000200000" is out of range for type integer

我在 运行heroku 上进行抽取时遇到错误。我可以 运行 在本地耙地,但由于某些原因,这在实时环境中不起作用。我看过一些关于 bigint 整数的帖子,但我什至不确定这个错误发生在哪里或者为什么?

C:\Sites\jeepjig>heroku rake scraper:scrape
Your version of git is 1.9.4.. Which has serious security vulnerabilities.
More information here: https://blog.heroku.com/archives/2014/12/23/update_your_git_clients_on_windows_and_os_x
WARNING: `heroku rake` has been deprecated. Please use `heroku run rake` instead.
Running `rake scraper:scrape` attached to terminal... up, run.8759
PG::NumericValueOutOfRange: ERROR:  value "150000200000" is out of range for type integer
: INSERT INTO "posts" ("body", "created_at", "external_url", "heading", "make", "mileage", "model", "price", "timestamp", "title_status", "transmiss
ion", "updated_at", "year") VALUES (, , , , , , , , , , , , ) RETURNING "id"
rake aborted!
ActiveRecord::StatementInvalid: PG::NumericValueOutOfRange: ERROR:  value "150000200000" is out of range for type integer
: INSERT INTO "posts" ("body", "created_at", "external_url", "heading", "make", "mileage", "model", "price", "timestamp", "title_status", "transmiss
ion", "updated_at", "year") VALUES (, , , , , , , , , , , , ) RETURNING "id"
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/connection_adapters/postgresql_adapter.rb:834:in `get_last_result'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/connection_adapters/postgresql_adapter.rb:834:in `block in exec_cache'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract_adapter.rb:373:in `block in log'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract_adapter.rb:367:in `log'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/connection_adapters/postgresql_adapter.rb:831:in `exec_cache'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/connection_adapters/postgresql/database_statements.rb:138:in `exec_query'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/connection_adapters/postgresql/database_statements.rb:177:in `exec_insert'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract/database_statements.rb:95:in `insert'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract/query_cache.rb:14:in `insert'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/relation.rb:64:in `insert'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/persistence.rb:503:in `_create_record'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/attribute_methods/dirty.rb:87:in `_create_record'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/callbacks.rb:306:in `block in _create_record'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_support/callbacks.rb:113:in `call'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_support/callbacks.rb:113:in `call'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_support/callbacks.rb:215:in `block in halting_and_conditional'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_support/callbacks.rb:86:in `call'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_support/callbacks.rb:86:in `run_callbacks'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/callbacks.rb:306:in `_create_record'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/timestamp.rb:57:in `_create_record'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/persistence.rb:483:in `create_or_update'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/callbacks.rb:302:in `block in create_or_update'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_support/callbacks.rb:113:in `call'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_support/callbacks.rb:113:in `call'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_support/callbacks.rb:166:in `block in halting'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_support/callbacks.rb:86:in `call'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_support/callbacks.rb:86:in `run_callbacks'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/callbacks.rb:302:in `create_or_update'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/persistence.rb:103:in `save'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/validations.rb:51:in `save'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/attribute_methods/dirty.rb:21:in `save'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/transactions.rb:268:in `block (2 levels) in save'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/transactions.rb:329:in `block in with_transaction_returning_status'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract/database_statements.rb:201:in `block in transac
tion'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract/database_statements.rb:209:in `within_new_trans
action'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract/database_statements.rb:201:in `transaction'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/transactions.rb:208:in `transaction'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/transactions.rb:326:in `with_transaction_returning_status'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/transactions.rb:268:in `block in save'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/transactions.rb:283:in `rollback_active_record_state!'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/transactions.rb:267:in `save'
/app/lib/tasks/scraper.rake:62:in `block (4 levels) in <top (required)>'
/app/lib/tasks/scraper.rake:38:in `each'
/app/lib/tasks/scraper.rake:38:in `block (3 levels) in <top (required)>'
/app/lib/tasks/scraper.rake:13:in `loop'
/app/lib/tasks/scraper.rake:13:in `block (2 levels) in <top (required)>'
Tasks: TOP => scraper:scrape
(See full trace by running task with --trace)

"150000200000" 是使用 INSERT INTO "posts" ("body", "created_at", "external_url", "heading", "make", "mileage", "model", "price", "timestamp", "title_status", "transmission", "updated_at", "year")... 语句插入的字段之一中的值。

应将相应字段从整数更改为 bigint 以解决此问题。或者如果字段不必是数字,则更改为字符串。

问题不是发生在本地,而是发生在 heroku 上,这很可能是因为 Heroku 抓取过程 运行 针对的是未包含在本地脚本中的站点。

最好添加额外的 logging/puts 语句来确定哪个字段的值是 "150000200000",然后适当地处理该字段。