You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

执行php artisan migrate报错:Call to undefined method Illuminate\Support\Fluent::after()

解决Laravel迁移中Call to undefined method Illuminate\Support\Fluent::after()错误

错误原因

该错误是由于你使用的Laravel版本中,unsignedInteger()方法返回的是Illuminate\Support\Fluent实例,而这个实例没有after()方法。在旧版本Laravel(如5.8及更早)中,unsignedInteger并不支持链式调用after,需要改用integer()配合unsigned()的写法。

修复方案

修改迁移文件中的字段定义代码,将:

$table->unsignedInteger('cod_esocial')->after('cod');

替换为:

$table->integer('cod_esocial')->unsigned()->after('cod');

修改后的完整迁移文件如下:

<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class AlterTableRhRacaCorAddCodEsocial extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('rh_raca_cor', function(Blueprint $table){
            $table->integer('cod_esocial')->unsigned()->after('cod');
        });

        DB::statement("update rh_raca_cor set cod_esocial = case 
            when id = 1 then 4
            when id = 2 then 1
            when id = 3 then 5
            when id = 4 then 3
            when id = 5 then 2
            else 6 end;
        ");
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('rh_raca_cor', function(Blueprint $table){
            $table->dropColumn('cod_esocial');
        });
    }
}

验证修复

保存修改后的迁移文件,重新执行:

php artisan migrate

即可正常运行迁移。

内容的提问来源于stack exchange,提问作者Bruno Silva

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.13 08:45:30