由于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
的{{1}}设为order
到equal
。
item->id
答案 0 :(得分:2)
2,147,483,647(或十六进制7FFF,FFFF16)是计算中32位带符号二进制整数的最大正值。因此,它是许多编程语言中声明为整数(例如int)的变量的最大值。
您应该将 DB 中的 INTEGER 更改为 VARCHAR ,以查看是否可以解决您的错误,如果不能,请检查脚本语言,则可能有超过2,147,483,647的操作,因此仅显示其最大值。
答案 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了解更多信息。