由于capacity
的variable
,我的数据库出现问题。因此,我将id
从integer
更改为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
equal
至item->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');
}
您是否回滚了迁移并再次迁移了?如果您的表已经创建,则必须创建一个新的迁移,更改所需字段
Schema::table('items', function (Blueprint $table) {
$table->bigInteger('id')->unsigned()->change();
});
然后再次使用]进行迁移>
php artisan migrate
但是这不是最好的事情
MySql具有其handling auto increments的方法。
您可以使用以下方法在laravel中创建较大的增量:>
$table->bigIncrements('id');
See documentation了解更多信息。