1

我想知道是否应该在 Laravel github 上打开一个问题,但我不确定这是一个 Laravel 问题,可能是 Eloquent 或 MariaDB。


最近升级到 Laravel 6.0的问题。当我尝试重新安装我的项目(使用空数据库)并执行php artisan migrate时,第一次迁移失败。该文件仅包含一个表创建:

/**
 * Run the migrations.
 *
 * @return void
 */
public function up()
{
    Schema::create('ltm_translations', function(Blueprint $table)
    {
        $table->increments('id');
        $table->integer('status')->default(0);
        $table->string('locale');
        $table->string('group');
        $table->string('key');
        $table->text('value')->nullable();
        $table->timestamps();
    });
}

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

错误是因为生成了错误的SQL。第二->default(0)列上的 被翻译成status int not null default ('0')

括号里的东西导致我的数据库抛出异常。这是生成的完整 SQL(从错误消息中提取)。

create table `ltm_translations` (`id` int unsigned not null auto_increment primary key, `status` int not null default ('0'), `locale` varchar(255) not null,
  `group` varchar(255) not null, `key` varchar(255) not null, `value` text null, `created_at` timestamp null, `updated_at` timestamp null) default character set utf8 collate 'utf8_bin' engine = innodb`

如果我复制粘贴此查询并替换('0')0它有效。
(0)('0')失败。

官方文档告诉我这是一个有效的语法,带有表达式等,但它提到了一些关于 10.2 版本的内容。

我的 MariaDB 版本回复:

mariadb --version
mariadb  Ver 15.1 Distrib 10.1.40-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2

问题
是我的 MariaDB 版本的问题吗?
我可以强制 Eloquent 生成与我的 MariaDB 版本兼容的语法,还是强制将 mariaDB 升级到 10.2+?

由于生产操作系统版本(Ubuntu 18.04)不正式支持此功能,这将是一个可怕的问题,欢迎任何与生产服务器兼容的解决方案。

感谢您的时间 !

4

1 回答 1

1

从 laravel 6.0.3 开始工作

该问题已通过 laravel 6.0.3 修复

6.0.3 之前的工作组合

  • Laravel 5.8 mysql 5.7.27工作
  • Laravel 6.0.2 mysql 5.7.27 不起作用
  • Laravel 6.0.2 mysql 8.0.13工作

在解决此问题之前,您似乎可以将 Laravel 降级到 5.8 或将 mysql 升级到 8。

使用 docker 在您的开发机器上升级到 mysql 8

如果您决定升级到 mysql 8.0.13,请确保将default-authentication-plugin=mysql_native_password. 那是 AFAIK 一个 php 问题,而不是 laravel 问题。

供你参考:

$ ls -l
drwxrwxr-x 7 thomas thomas 4096 Sep 11 10:28 data
-rw-rw-r-- 1 thomas thomas   61 Sep 11 10:11 php-compatible-password.cnf
-rwxrw-r-- 1 thomas thomas  316 Sep 11 10:14 start.sh

php-compatible-password.cnf:

[mysqld]
default-authentication-plugin=mysql_native_password

开始.sh:

#!/usr/bin/env bash

docker run --rm -v "$PWD/php-compatible-password.cnf":/etc/mysql/conf.d/php-compatible-password.cnf -v "$PWD/data":/var/lib/mysql --user 1000:1000 --name mydb-mysql8 -e MYSQL_ROOT_PASSWORD=secret -e MYSQL_DATABASE=homestead -e MYSQL_USER=homestead -e MYSQL_PASSWORD=secret -d mysql:8

laravel .env:

…
DB_CONNECTION=mysql
DB_HOST=172.17.0.2
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
…

其中 172.17.0.2 是

docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' mydb-mysql8
于 2019-09-11T08:41:48.337 回答