使用ubuntu 18.04在远程服务器上上传laravel 9项目时,迁移时出错:

2023_01_18_053125_create_user_meetings_table ............................................................................................ 1ms FAIL

Illuminate\Database\QueryException

SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default value for 'created_at' (SQL: create table `user_meetings` (`id` bigint unsigned not null auto_increment primary key, `name` varchar(255) not null, `user_name` varchar(100) not null, `user_email` varchar(100) not null, `user_quiz_request_id` bigint unsigned not null, `appointed_at` timestamp null, `status` enum('W', 'A', 'M', 'C', 'D') not null comment 'W => Waiting for review,  A => Accepted for meeting, M=>Marked for future contacts, C=>Cancelled, D-Declined', `created_at` timestamp not null, `updated_at` timestamp null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')

迁移文件具有:

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('user_meetings', function (Blueprint $table) {
            $table->id();

            $table->string('name', 255);
            $table->string('user_name', 100);
            $table->string('user_email', 100);

            $table->bigInteger('user_quiz_request_id')->unsigned();
            $table->foreign('user_quiz_request_id', 'user_meetings_user_quiz_request_id_foreign')->references('id')->on('user_quiz_requests')->onUpdate('RESTRICT')->onDelete('CASCADE');


            $table->timestamp('appointed_at')->nullable();

            $table->enum('status', ['W', 'A', 'M', 'C', 'D'])->comment('W => Waiting for review,  A => Accepted for meeting, M=>Marked for future contacts, C=>Cancelled, D-Declined');

            $table->timestamp('created_at');
            $table->timestamp('updated_at')->nullable();
            $table->index(['status', 'user_email', 'appointed_at'], 'user_meetings_status_user_email_appointed_at_index');
            $table->index(['user_quiz_request_id', 'user_email', 'status'], 'user_meetings_user_quiz_request_id_user_email_status_index');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('user_meetings');
    }
};

我使用以下选项创建了数据库:

quizzes utf8_general_ci

我想知道错误信息"utf8mb4_unicode_ci"是从哪里提到的,因为我用"utf8_General_ci"选项创建了数据库?

还可以判断phpmyadmin中创建的表,请参阅:https://prnt.sc/U53Vi-vKW8oz

为什么会出错,因为是表创建语句,而不是添加行?

谢谢!

推荐答案

使用Laravel的Timestamp()方法

Laravel has a built-in method to create these columns for you: timestamps().
The created_at and updated_at columns will be created for you.

在迁移过程中,您可以这样称呼它:

$table->timestamps();

See documentation:
Laravel migrations: timestamps()

Laravel相关问答推荐

Laravel Livewire与自定义JS有关的多姆问题

如何使用 Laravel 进行继承

Laravel 5.2 无法打开 laravel.log

为什么 laravel 模型会重复一组数据以及如何(如果可能)只有一组数据?

Laravel Blade - 产生内部部分

如何为路由 laravel 5 使用OR中间件

在 laravel 5 中的表单请求验证后传递旧输入

Laravel 4 如何监听模型事件?

Laravel 干预图像 GD 库扩展

Laravel 从现有模型生成迁移

使用模型工厂、一对一和一对多关系定义 Laravel 外键,而不创建不必要的模型

如何从 Windows 命令提示符在 Laravel 中运行 PHPUnit

Laravel 动作未定义

如何调试 Laravel 框架?

WhereHas Laravel 中的关系计数条件是什么

脚本 php artisan clear-compiled 处理 pre-update-cmd 事件返回错误(Laravel 4.1 升级)

如果 Laravel 中的值不为空,如何验证输入字段

如何判断 Laravel 集合是否为空?

如何从 PHPUnit 测试设置运行 Laravel 数据库 seeder 机?

Laravel Mix:更新 Node.js 依赖项