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