如何在laravel的第一列之前添加新列?

Neh*_*eha 1 php laravel laravel-migrations

我需要首先使用 laravel 迁移在 Sql 中添加一列。我可以使用 after 在任何地方添加新列:

  Schema::table('tasks', function (Blueprint $table) {
        if (Schema::hasColumn('tasks', 'assigned_to_id') == false) {
                $table->integer('assigned_to_id')->after('status');
        }
  });
Run Code Online (Sandbox Code Playgroud)

表有以下字段: project_id , module_id

我需要在 project_id 之前添加列“id”。如何实现这一目标?提前致谢!

Has*_*ana 5

您可以使用$table->integer('id')->first()添加id为第一列