首页 > 解决方案 > 迁移中的默认值变成 SQL 错误

问题描述

我正在尝试将我的代码从 Laravel 5.8 更新到 Laravel 6.0。当我尝试迁移数据库时,出现 SQL 语法错误。

移民

Schema::create('stocks', function (Blueprint $table) {
    $table->increments('id');
    $table->unsignedInteger('product_id');
    $table->unsignedInteger('initial_price');
    $table->unsignedInteger('quantity');
    $table->unsignedInteger('price');
    $table->string('language')->default("EN");
    $table->string('state', 2)->default('MT');
    $table->string('idArticleMKM')->nullable(); //idArticle from mkm
    $table->foreign('product_id')->references('id')->on('products');
    $table->timestamps();
});

错误

SQLSTATE[42000]:语法错误或访问冲突:1064 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 1 行的 '('EN')、state varchar(2) not null default ('MT')、idArticleMKMvarchar(1023)' 附近使用正确的语法(SQL:create table stocks( idint unsigned not null auto_increment 主键, product_idint unsigned not null, initial_priceint unsigned not null, quantityint unsigned not null, priceint unsigned not null, languagevarchar(1023) not null default ('EN'), statevarchar(2) not null default ( 'MT'), idArticleMKMvarchar(1023) null, created_attimestamp null, updated_attimestamp null) 默认字符集 utf8mb4 collat​​e 'utf8mb4_unicode_ci')

标签: eloquentlaravel-6

解决方案



推荐阅读