php - 如何在 laravel 中向现有表添加新列

标签 php mysql laravel-5

我正在我的表格任务中添加新的列名标题。但是我得到一个错误,该列在该表中不存在。谁能帮我解决这个错误。这是我的代码:

php artisan make:migration add_title_to_tasks_table --table="tasks" 然后添加这段代码

Schema::table('tasks', function (Blueprint $table) { 
  $table->string('title');
});

创建新的表文件

最佳答案

更改表并添加列。

     /**
     * Run the migrations.
     *
     * @return void
     */
    public function up() {
        Schema::table('tasks', function (Blueprint $table) {

            $table->string('title')->after('id');

           // to change column datatype or change it to `nullable` 
           // or set default values , this is just example

           $table->string('title')->default('Test')->change(); 

        });
    }

您可以在此处引用文档,Laravel Migration

关于php - 如何在 laravel 中向现有表添加新列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49129893/

相关文章:

php - 拉拉维尔 ORM : select distinct by DATE for each user

php - 如何将选项字段中的两个值发布到表中的一列中

php - Laravel 5 redirect()->back() 没有按预期工作

php:如何在这个结构中实现命名空间

php - 如何使用GCM向应用程序推送消息?

php - Magento:如何将 'catalog/category' 字段左连接到 'sales/order_item' 集合?

php - 在 Laravel 代码冲突中加载 phpBB

php - MySQL:选择类别、子类别和品牌。只有当它们存在时

php - 您如何处理 Mysql SP 无法使用默认参数的情况?

php - 如何以 Laravel 方式执行此连接查询