为什么我的数据库仍然显示 2147483647 错误?

why my database still showing 2147483647 error?

由于 variablecapacity,我的数据库出现问题。 因此,我将 idinteger 更改为 bigInteger,如下所示。 id 将存储条码编号。

class CreateItemsTable extends Migration
{
public function up()
{
    Schema::create('items', function (Blueprint $table) {
        $table->bigInteger('id')->unsigned();
        $table->string('name',100);
        $table->decimal('buying_price', 5, 2);
        $table->timestamps();
    });
}

但是,当我尝试从其他控制器访问项目 table 时,页面显示此错误

No query results for model [App\Item] 2147483647

这就是我的 controller 的样子。我想让我的 item_id for order equalitem->id.

  public function store(Request $request)
  {
    $this->validate($request, [
        'item_id'=>'required|integer',
        'quantity'=>'required|integer',
    ]);

    $item=Item::FindOrFail($request->item_id);

    $order=new Order;
    $order->status=$request->get('status');
    $order->item_id=$item->id;
    if ($request->get('status')=='Complete') {
        $item->quantity += $request->input('quantity');
    }
    $order->quantity=$request->input('quantity');

    $order->save();
    $item->save();

    return redirect('/Order')->with('success','Order added');
}

您是否回滚了迁移并再次迁移?如果您的 table 已经创建,您必须创建一个新的迁移,更改想要的字段

Schema::table('items', function (Blueprint $table) {
    $table->bigInteger('id')->unsigned()->change();
});

然后使用

再次迁移
php artisan migrate

但这不是最好的选择

MySql 有其方法 handling auto increments.

您可以使用

在 laravel 中创建较大的增量
$table->bigIncrements('id');

See documentation 了解更多信息。

数字2,147,483,647(或十六进制7FFF,FFFF16)是32位有符号二进制整数在计算中的最大正值。因此,它是许多编程语言中声明为整数(例如 int)的变量的最大值。

您应该在 DB 中将 INTEGER 更改为 VARCHAR 以查看是否修复你的错误,如果没有,检查你的脚本语言,可能有超过2,147,483,647的操作,所以只显示它的最大值。