【问题标题】:Getting Numeric value out of range, but I've created it BigInt让数值超出范围,但我已经创建了 BigInt
【发布时间】:2019-11-15 06:42:09
【问题描述】:

我有一张表,其中一列是 request_id,它在迁移中定义如下:

$table->bigInteger('request_id')->index()->unsigned()->nullable();

当我在表结构中查看 phpmyadmin 时,它说

bigint(20)      UNSIGNED

我正在向我的 api 发出请求,并通过此值发送:1562247865319

$requestLog = new RequestLog();
$requestLog->request_id = 1562247865319;
$requestLog->save();

此代码出错并返回超出范围的数值:1264 超出范围

真正奇怪的是,当我在 phpmyadmin 中时,我可以手动将该列的值设置为比 1562247865319 大得多的值,但是当我通过我的 laravel 模型进行设置时,它不喜欢它。

编辑

错误信息是

SQLSTATE[22003]: Numeric value out of range: 1264 Out of range value for column 'request_id' at row 1 (SQL: insert into `request_logs` (`ip`, `submitted_user_name`, `url`, `full_url`, `method`, `request_id`, `request_data`, `api_user_id`, `updated_at`, `created_at`) values (..., ..., ..., http://..../api/..., POST, 1562247865319, {"request_id":"1562248616206"}, 2, 2019-07-04 14:57:00, 2019-07-04 14:57:00))

【问题讨论】:

  • 请我们总是看到完整和完整的错误消息!不是它的摘要
  • 您的PHP_INT_MAX 值是多少?
  • @Haru int size 8, int max 9223372036854775807

标签: php sql laravel


【解决方案1】:

我觉得这个问题和this一样。

尝试将任何 UNSIGNED 整数更改为 SIGNED。

【讨论】:

  • 当我将其更改为已签名并将其添加到列中时,由于某种原因它使值变为负数...
  • 是同一个数字吗?
  • 对不起,NO,这不是同一个值
  • 我尝试分配 1562247865319 并将其存储为 -1120230425
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-11-05
  • 2012-07-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-18
相关资源
最近更新 更多