這是我的表結構Laravel插入一個BIGINT到MySQL錯誤
SET NAMES utf8;
SET foreign_key_checks = 0;
SET time_zone = '+07:00';
SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';
DROP TABLE IF EXISTS `merchants`;
CREATE TABLE `merchants` (
`id` bigint(20) NOT NULL,
`name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`url` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`address` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`work_hour` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`created_at` datetime NOT NULL,
`updated_at` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
我的模型
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
/**
* @property $name
* Class Merchant
* @package App
*/
class Merchant extends Model
{
/**
* The table associated with the model
* @var string
*/
protected $table = "merchants";
//
protected $fillable = [
"name", "url", "address", "work_hour", "id"
];
public $incrementing = false;
}
回聲PHP_INT_SIZE; // 8 回聲PHP_INT_MAX; // 9223372036854775807
每次,我插入新的紀錄ID是一個BIGINT,它總是在DB
$merchant->id = $newId1;
$merchant->name = $request->name;
$merchant->url = $request->url;
$merchant->address = $request->address;
$merchant->work_hour = 'a';
$merchant->created_at = date('Y-m-d h:i:s');
$merchant->updated_at = date('Y-m-d h:i:s');
$merchant->save();
$ newId1 = 4550103638072627879錯誤的;但在MySQL顯示-2144066090
請幫
DB ID字段也是bigint。 –
是的,如果它是bigint你應該存儲你的值作爲字符串不是一個整數。 – Muthu17
爲什麼?因爲PHP可以處理這個整數,mysql也可以,爲什麼我們需要將它改爲string? 'join'會發生什麼? –