【发布时间】:2022-01-23 11:55:38
【问题描述】:
我正在迁移表:
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateExamsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('exams', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->enum('type',['iq','math','geo','gen']);
$table->string('notes');
$table->boolean('vip');
$table->string('rate');
$table->integer('hardness');
$table->string('quode');
$table->timestamp('bornline');
$table->timestamp('deadline', $precision = '0000-00-00');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('exams');
}
}
返回此错误的 cmd
照亮\数据库\查询异常
SQLSTATE[42000]:语法错误或访问冲突:1067 无效 'deadline' 的默认值 (SQL: create table
exams(idbigint unsigned not null auto_increment 主键,namevarchar(191) 不是 null,typeenum('iq', 'math', 'geo', 'gen') not null,notesvarchar(191) 不为空,viptinyint(1) 不为空,ratevarchar(191) 不为空,hardnessint 不为空,quodevarchar(191) 不为空,bornline时间戳不为空,deadline时间戳不为空,created_attimestamp null,updated_attimestamp null) 默认 字符集 utf8mb4 collate 'utf8mb4_unicode_ci')在 C:\Users\xxgam\OneDrive\Desktop\projects\deneme\vendor\laravel\framework\src\Illuminate\Database\Connection.php:705
701▕ // 如果尝试运行查询时发生异常,我们将格式化错误
702▕ // 包含与 SQL 的绑定的消息,这将使此异常成为一个
703▕ // 对开发人员更有帮助,而不仅仅是数据库的错误。
704▕ catch (Exception $e) { ➜ 705▕ throw new QueryException(
706▕ $query, $this->prepareBindings($bindings), $e
707▕);
708▕ }
709▕}C:\Users\xxgam\OneDrive\Desktop\projects\deneme\vendor\laravel\framework\src\Illuminate\Database\Connection.php:494 PDOException::("SQLSTATE[42000]: 语法错误或访问冲突:1067 'deadline' 的默认值无效")
C:\Users\xxgam\OneDrive\Desktop\projects\deneme\vendor\laravel\framework\src\Illuminate\Database\Connection.php:494 PDOStatement::execute()
【问题讨论】:
-
我从 laravel 创建它我无法修改 SQL 语法
-
应该是
$table->timestamp('deadline', $precision = 0); -
语法错误或访问冲突:1067 'deadline' 的默认值无效
-
'0000-00-00' 不允许
标签: mysql laravel migration database-migration