doctrine:migrations:migrate:SQLSTATE[42000]:语法错误或访问冲突:1064
doctrine:migrations:migrate : SQLSTATE[42000]: Syntax error or access violation: 1064
我正在尝试使用以下命令迁移生产环境中的数据库 (MySQL 5.6):php bin/console doctrine:migrations:migrate
我把这个放在 Doctrine.yalm:
doctrine:
dbal:
url: '%env(resolve:DATABASE_URL)%'
driver: 'pdo_mysql'
server_version: '5.6'
不知道为什么会出现错误信息:
Migration 20200426103129 failed during Execution. Error An exception
occurred while executing 'CREATE TABLE user (id INT AUTO_INCREMENT NOT
NULL, email VARCHAR(180) NOT NULL, roles JSON NOT NULL, password
VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_8D93D649E7927C74 (email),
PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE
utf8mb4_unicode_ci ENGINE = InnoDB':
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an
error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near 'JSON NOT NULL,
password VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_8D93D649E7927C7' at
line 1 13:03:10 ERROR [console] Error thrown while running command
"doctrine:migrations:migrate". Message: "An exception occurred while
executing 'CREATE TABLE user (id INT AUTO_INCREMENT NOT NULL, email
VARCHAR(180) NOT NULL, roles JSON NOT NULL, password VARCHAR(255) NOT
NULL, UNIQUE INDEX UNIQ_8D93D649E7927C74 (email), PRIMARY KEY(id))
DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE =
InnoDB':\n\nSQLSTATE[42000]: Syntax error or access violation: 1064
You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near 'JSON NOT NULL, password VARCHAR(255) NOT NULL, UNIQUE INDEX
UNIQ_8D93D649E7927C7' at line 1" ["exception" =>
Doctrine\DBAL\Exception\SyntaxErrorException^ { …},"command" =>
"doctrine:migrations:migrate","message" => """ An exception occurred
while executing 'CREATE TABLE user (id INT AUTO_INCREMENT NOT NULL,
email VARCHAR(180) NOT NULL, roles JSON NOT NULL, password
VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_8D93D649E7927C74 (email),
PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE
utf8mb4_unicode_ci ENGINE = InnoDB':\n \n SQLSTATE[42000]: Syntax
error or access violation: 1064 You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version for the
right syntax to use near 'JSON NOT NULL, password VARCHAR(255) NOT
NULL, UNIQUE INDEX UNIQ_8D93D649E7927C7' at line 1 """]
In AbstractMySQLDriver.php line 79:
An exception occurred while executing 'CREATE TABLE user (id INT
AUTO_INCREMENT NOT NULL, email VARCHAR(180) NOT NULL, roles JSON NOT
NULL, password VARCHAR(255) NOT NULL, UNIQUE INDEX
UNIQ_8D93D649E7927C74 (email), PRIMARY KEY(id)) DEFAULT CHARACTER SET
utf8mb4 COLLA TE utf8mb4_unicode_ci ENGINE = InnoDB':
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an
error in your SQL syntax; check the manual that corresponds to you
r MySQL server version for the right syntax to use near 'JSON NOT
NULL, password VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_8D93D649E792
7C7' at line 1
在 PDOConnection.php 第 90 行:
SQLSTATE[42000]:语法错误或访问冲突:1064 您的 SQL 语法有误;查看与您相对应的手册
r MySQL 服务器版本,用于在 'JSON NOT NULL 附近使用正确的语法,密码 VARCHAR(255) NOT NULL,UNIQUE INDEX UNIQ_8D93D649E792
第 1 行的 7C7'
在 PDOConnection.php 第 88 行:
SQLSTATE[42000]:语法错误或访问冲突:1064 您的 SQL 语法有误;查看与您相对应的手册
r MySQL 服务器版本,用于在 'JSON NOT NULL 附近使用正确的语法,密码 VARCHAR(255) NOT NULL,UNIQUE INDEX UNIQ_8D93D649E792
第 1 行的 7C7'
JSON 列类型在 MySQL 5.7.8 之前不可用,因此您无法将此类列添加到数据库中
我自己解决。
有很多与此问题相关的内容,但总是给出部分答案。
对于遇到此问题的其他人,这里是完整的解释:
使用 Symfony 创建用户实体时,您将有一个 JSON 列来管理角色。
如果您的 SQL 版本低于 5.7.8,您必须在 doctrine.yaml 文件中指明版本,如下所示:
doctrine:
dbal:
url: '%env(resolve:DATABASE_URL)%'
driver: 'pdo_mysql'
server_version: '5.6'
这还不是全部:如果您在尝试迁移数据库时遇到错误消息 SQLSTATE[42000],您还必须删除 src/migration 文件夹中生成的文件。
我正在尝试使用以下命令迁移生产环境中的数据库 (MySQL 5.6):php bin/console doctrine:migrations:migrate
我把这个放在 Doctrine.yalm:
doctrine:
dbal:
url: '%env(resolve:DATABASE_URL)%'
driver: 'pdo_mysql'
server_version: '5.6'
不知道为什么会出现错误信息:
Migration 20200426103129 failed during Execution. Error An exception occurred while executing 'CREATE TABLE user (id INT AUTO_INCREMENT NOT NULL, email VARCHAR(180) NOT NULL, roles JSON NOT NULL, password VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_8D93D649E7927C74 (email), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB':
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'JSON NOT NULL, password VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_8D93D649E7927C7' at line 1 13:03:10 ERROR [console] Error thrown while running command "doctrine:migrations:migrate". Message: "An exception occurred while executing 'CREATE TABLE user (id INT AUTO_INCREMENT NOT NULL, email VARCHAR(180) NOT NULL, roles JSON NOT NULL, password VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_8D93D649E7927C74 (email), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB':\n\nSQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'JSON NOT NULL, password VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_8D93D649E7927C7' at line 1" ["exception" => Doctrine\DBAL\Exception\SyntaxErrorException^ { …},"command" => "doctrine:migrations:migrate","message" => """ An exception occurred while executing 'CREATE TABLE user (id INT AUTO_INCREMENT NOT NULL, email VARCHAR(180) NOT NULL, roles JSON NOT NULL, password VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_8D93D649E7927C74 (email), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB':\n \n SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'JSON NOT NULL, password VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_8D93D649E7927C7' at line 1 """]
In AbstractMySQLDriver.php line 79: An exception occurred while executing 'CREATE TABLE user (id INT AUTO_INCREMENT NOT NULL, email VARCHAR(180) NOT NULL, roles JSON NOT
NULL, password VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_8D93D649E7927C74 (email), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLA TE utf8mb4_unicode_ci ENGINE = InnoDB':SQLSTATE[42000]: Syntax error or access violation: 1064 You have an
error in your SQL syntax; check the manual that corresponds to you
r MySQL server version for the right syntax to use near 'JSON NOT NULL, password VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_8D93D649E792
7C7' at line 1
在 PDOConnection.php 第 90 行:
SQLSTATE[42000]:语法错误或访问冲突:1064 您的 SQL 语法有误;查看与您相对应的手册
r MySQL 服务器版本,用于在 'JSON NOT NULL 附近使用正确的语法,密码 VARCHAR(255) NOT NULL,UNIQUE INDEX UNIQ_8D93D649E792
第 1 行的 7C7'
在 PDOConnection.php 第 88 行:
SQLSTATE[42000]:语法错误或访问冲突:1064 您的 SQL 语法有误;查看与您相对应的手册
r MySQL 服务器版本,用于在 'JSON NOT NULL 附近使用正确的语法,密码 VARCHAR(255) NOT NULL,UNIQUE INDEX UNIQ_8D93D649E792
第 1 行的 7C7'
JSON 列类型在 MySQL 5.7.8 之前不可用,因此您无法将此类列添加到数据库中
我自己解决。 有很多与此问题相关的内容,但总是给出部分答案。
对于遇到此问题的其他人,这里是完整的解释:
使用 Symfony 创建用户实体时,您将有一个 JSON 列来管理角色。 如果您的 SQL 版本低于 5.7.8,您必须在 doctrine.yaml 文件中指明版本,如下所示:
doctrine:
dbal:
url: '%env(resolve:DATABASE_URL)%'
driver: 'pdo_mysql'
server_version: '5.6'
这还不是全部:如果您在尝试迁移数据库时遇到错误消息 SQLSTATE[42000],您还必须删除 src/migration 文件夹中生成的文件。