ActiveRecord :: StatementInvalid:PG :: NumericValueOutOfRange:ERROR:值“150000200000”超出了整数类型的范围

时间:2015-03-15 03:03:59

标签: ruby-on-rails heroku-postgres

我在heroku上运行rake时遇到错误。我可以在当地运行耙子,但由于某种原因,这不适用于现场环境。我看过一些关于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 ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13) 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 ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13) 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)

1 个答案:

答案 0 :(得分:2)

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

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

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

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