【问题标题】:How to add new column before first column in laravel?如何在laravel的第一列之前添加新列?
【发布时间】:2019-11-09 09:51:57
【问题描述】:

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

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

表格有以下字段: project_id , module_id

我需要在 project_id 之前添加列“id”。 如何做到这一点? 提前致谢!

【问题讨论】:

  • 你能试试看使用after() 2 次是否有效?

标签: php laravel laravel-migrations


【解决方案1】:

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

【讨论】:

  • 谢谢@Hasta Dhana!
猜你喜欢
  • 2019-03-13
  • 1970-01-01
  • 2015-12-12
  • 2018-06-28
  • 1970-01-01
  • 2016-09-09
  • 2010-11-17
  • 1970-01-01
  • 2015-05-17
相关资源
最近更新 更多