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

问题描述 投票:0回答:1

由于capacityvariable,我的数据库出现问题。因此,我将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();
    });
}

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

没有模型[App \ Item] 2147483647的查询结果

这是我的controller的样子。我想将我的item_id设置为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');
}
php mysql laravel biginteger
1个回答
1
投票

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

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

然后再次使用]进行迁移>

php artisan migrate

但是这不是最好的事情

MySql具有其handling auto increments的方法。

您可以使用以下方法在laravel中创建较大的增量:>

$table->bigIncrements('id');

See documentation了解更多信息。

© www.soinside.com 2019 - 2024. All rights reserved.