laravel创建新表迁移时出现语法错误或访问冲突问题



我有以下创建表迁移在我的laravel应用程序

<?php
use IlluminateDatabaseMigrationsMigration;
use IlluminateDatabaseSchemaBlueprint;
use IlluminateSupportFacadesSchema;
class CreateSchedulesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('schedules', function (Blueprint $table) {
$table->bigIncrements('id');
$table->unsignedBigInteger('department_id')->nullable()->after('id');
$table->foreign('department_id')->references('id')->on('departments');
$table->string('schedule_name');
$table->date('schedule_start_date');
$table->date('schedule_end_date');
$table->date('schedule_actual_end_date');
$table->time('schedule_travel_time');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('schedules');
}
}

但是当我尝试运行这个迁移时,我得到一个错误说,

SQLSTATE[42000]: Syntax error or access violation: 1064SQL语法错误;请查阅与您的产品相对应的手册MariaDB服务器版在id之后使用的正确语法schedule_namevarchar(255)不空,schedule_start_date日期…SQL:创建表schedules(idauto_increment主键,department_idbigint unsigned nullafterid,schedule_namevarchar(255) not null,schedule_start_datedate not null,schedule_end_datedate notschedule_actual_end_date日期不空,schedule_travel_timetime not null,created_attimestamp null,updated_attimestampNull)默认字符集utf8mb4 collate 'utf8mb4_unicode_ci')

我正在努力寻找问题所在,因为我无法在这里发现任何语法错误。

删除函数后面的代码。因为您正在创建迁移而不是更新。

public function up()
{
Schema::create('schedules', function (Blueprint $table) {
$table->bigIncrements('id');
$table->unsignedBigInteger('department_id')->nullable();
$table->foreign('department_id')->references('id')->on('departments');
$table->string('schedule_name');
$table->date('schedule_start_date');
$table->date('schedule_end_date');
$table->date('schedule_actual_end_date');
$table->time('schedule_travel_time');
$table->timestamps();
});
}

请查看laravel官方文档,上面写着

被用作列修饰符。

最新更新