【问题标题】:Default value in migration turns into SQL error迁移中的默认值变成 SQL 错误
【发布时间】:2020-01-14 06:22:17
【问题描述】:

我正在尝试将我的代码从 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 服务器版本,用于在 '('EN') 附近使用正确的语法,state varchar(2) not null default ('MT'), idArticleMKM varchar(1023)' at 第 1 行 (SQL: 创建表 stocks (id int unsigned not null auto_increment 主键,product_id int unsigned not null, initial_price int unsigned not null, quantity int unsigned not 空,price int 无符号非空,language varchar(1023) 非空 默认 ('EN'), state varchar(2) not null 默认 ('MT'), idArticleMKM varchar(1023) 空,created_at 时间戳空, updated_attimestamp null) 默认字符集 utf8mb4 collat​​e 'utf8mb4_unicode_ci')

【问题讨论】:

    标签: eloquent laravel-6


    【解决方案1】:

    【讨论】:

      猜你喜欢
      • 2016-10-06
      • 1970-01-01
      • 2020-04-17
      • 2019-07-27
      • 2014-07-10
      • 1970-01-01
      • 2016-11-16
      • 2014-11-19
      • 1970-01-01
      相关资源
      最近更新 更多