SQLSTATE[42000]:语法错误或访问冲突:尝试迁移时给出 1064
SQLSTATE[42000]: Syntax error or access violation: 1064 Is given when attempting to migrate
我正在尝试使用以下方法迁移 3 个模型:
php artisan migrate
但是我得到了标题中提到的错误
这是错误消息的其余部分:
SQLSTATE[42000]: Syntax error or access violation: 1064
You have an error in your SQL syntax;
check the manual that corresponds to your
MariaDB server version for the right syntax to use
near 'created_at) null, `updated_at`
timestamp(created_at) null, `created_at` times...' at line 1
这是我的代码:
Schema::create('v_users', function (Blueprint $table) {
$table->id('userid');
$table->string('full_Name');
$table->string('email');
$table->string('phone_No');
$table->string('role');
$table->timestamps('created_at');
$table->timestamps('updated_at');
Schema::create('vehicles', function (Blueprint $table) {
$table->id('v_id');
$table->foreign('user_id')->references('userid')->on('users')->onDelete('cascade');
$table->string('v_plate_no');
$table->string('v_brand');
$table->string('v_model');
$table->string('v_color');
$table->timestamps('created_at');
$table->timestamps('updated_at');
Schema::create('reports', function (Blueprint $table) {
$table->id('reportid');
$table->foreign('vehicleid')->references('v_id')->on('vehicles')->onDelete('cascade');
$table->string('title');
$table->string('description');
$table->timestamps('created_at');
$table->timestamps('updated_at');
我是一般编码的新手,非常感谢您的反馈,在此先感谢。
在您的迁移过程中,我最感兴趣的是您如何处理时间戳列。
timestamps
方法不带列名,看这里:
https://laravel.com/docs/master/migrations#column-method-timestamps
此方法的唯一参数是精度,如果您想对其进行自定义。现在你基本上指定了 created_at
的精度,我可以想象这会导致查询失败。
你只需要这样做...
$table->timestamps();
... 和 Laravel 将为您创建 created_at
和 updated_at
列。
如果您需要显式创建自己的时间戳列,请确保使用 timestamp()
方法(末尾没有 's'):
https://laravel.com/docs/master/migrations#column-method-timestamp
我正在尝试使用以下方法迁移 3 个模型:
php artisan migrate
但是我得到了标题中提到的错误 这是错误消息的其余部分:
SQLSTATE[42000]: Syntax error or access violation: 1064
You have an error in your SQL syntax;
check the manual that corresponds to your
MariaDB server version for the right syntax to use
near 'created_at) null, `updated_at`
timestamp(created_at) null, `created_at` times...' at line 1
这是我的代码:
Schema::create('v_users', function (Blueprint $table) {
$table->id('userid');
$table->string('full_Name');
$table->string('email');
$table->string('phone_No');
$table->string('role');
$table->timestamps('created_at');
$table->timestamps('updated_at');
Schema::create('vehicles', function (Blueprint $table) {
$table->id('v_id');
$table->foreign('user_id')->references('userid')->on('users')->onDelete('cascade');
$table->string('v_plate_no');
$table->string('v_brand');
$table->string('v_model');
$table->string('v_color');
$table->timestamps('created_at');
$table->timestamps('updated_at');
Schema::create('reports', function (Blueprint $table) {
$table->id('reportid');
$table->foreign('vehicleid')->references('v_id')->on('vehicles')->onDelete('cascade');
$table->string('title');
$table->string('description');
$table->timestamps('created_at');
$table->timestamps('updated_at');
我是一般编码的新手,非常感谢您的反馈,在此先感谢。
在您的迁移过程中,我最感兴趣的是您如何处理时间戳列。
timestamps
方法不带列名,看这里:
https://laravel.com/docs/master/migrations#column-method-timestamps
此方法的唯一参数是精度,如果您想对其进行自定义。现在你基本上指定了 created_at
的精度,我可以想象这会导致查询失败。
你只需要这样做...
$table->timestamps();
... 和 Laravel 将为您创建 created_at
和 updated_at
列。
如果您需要显式创建自己的时间戳列,请确保使用 timestamp()
方法(末尾没有 's'):
https://laravel.com/docs/master/migrations#column-method-timestamp