我有以下创建表迁移在我的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_name
varchar(255)不空,schedule_start_date
日期…SQL:创建表schedules
(id
auto_increment主键,department_id
bigint unsigned nullafterid
,schedule_name
varchar(255) not null,schedule_start_date
date not null,schedule_end_date
date notschedule_actual_end_date
日期不空,schedule_travel_time
time not null,created_at
timestamp null,updated_at
timestampNull)默认字符集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官方文档,上面写着
后被用作列修饰符。