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

Laravel执行php artisan migrate提示无迁移内容,添加customers表失败

问题描述

我在已执行过的迁移文件_create_students_table.php的up方法中添加了创建customers表的代码,但执行php artisan migrate时终端提示Nothing to migrate.,无法创建customers表。

终端输出

php artisan migrate

   INFO  Nothing to migrate.  

数据库现状

数据库截图

迁移文件代码

public function up()
{
    Schema::create('students', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->string('name');
        $table->string('nickname');
        $table->string('birth_date');
        $table->string('email');
        $table->string('phone');
        $table->string('password');
        $table->timestamps();
    });

    Schema::create('customers', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->string('name');
        $table->string('nickname');
        $table->string('birth_date');
        $table->string('email');
        $table->string('phone');
        $table->string('password');
        $table->timestamps();
    });
}
解决方案

Laravel的迁移系统通过migrations表记录已执行的迁移文件,你修改的这个迁移文件已经被标记为执行完成,因此直接运行migrate不会触发它的再次执行。以下是几种可行的解决方式:

  • 回滚后重新执行迁移
    如果该迁移是最近一次执行的,先回滚操作:

    php artisan migrate:rollback
    

    再重新执行迁移:

    php artisan migrate
    

    注意:此操作会删除已创建的students表,若表中已有数据,请先备份。

  • 创建新的迁移文件(推荐)
    不要修改已执行的迁移文件是Laravel迁移的最佳实践,应创建独立迁移来创建customers表:

    php artisan make:migration create_customers_table
    

    打开新生成的迁移文件,将创建customers表的代码移入其中,再执行迁移:

    php artisan migrate
    
  • 手动更新migrations表(不推荐)
    若不想回滚或创建新迁移,可手动删除migrations表中对应_create_students_table.php的记录,再重新执行php artisan migrate。此方式风险较高,生产环境禁止使用。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.11 18:31:07