2

I am trying make user via CLI: (symfony doc)

php bin/console make:user

This command create User.php entity which implements UserInterface.

But after command:

php bin/console doctrine:schema:update --force

I get errors:

In AbstractMySQLDriver.php line 79:

An exception occurred while executing 'CREATE TABLE user (id INT AUTO_INCREMENT NOT NULL, email VARCHAR(18 0) NOT NULL, roles JSON NOT NULL, password VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_8D93D649E7927C74 (emai l), 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 ma nual that corresponds to your MariaDB server version for the right syntax to use near 'JSON NOT NULL, pass word VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_8D93D649E7927C7' at line 1

In PDOConnection.php line 90:

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the ma nual that corresponds to your MariaDB server version for the right syntax to use near 'JSON NOT NULL, pass word VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_8D93D649E7927C7' at line 1

In PDOConnection.php line 88:

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the ma nual that corresponds to your MariaDB server version for the right syntax to use near 'JSON NOT NULL, pass word VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_8D93D649E7927C7' at line 1

EDIT:

Info about sql:

Server type: MariaDB

Server version: 10.1.31-MariaDB - mariadb.org binary distribution

Protocol version: 10

Lajdák Marek
  • 2,969
  • 8
  • 29
  • 58

2 Answers2

2

Your MariaDB has to be updated. You have a field with type=JSON (e.g. roles), but that is only available from 10.2+, you have version 10.1.


Also, the method you're using (update+ --force) isn't very Symfony 4. A better aproach would be:

php bin/console make:user 
php bin/console make:migration
php bin/console doctrine:migrations:migrate
Martijn
  • 15,791
  • 4
  • 36
  • 68
  • Thx, but i was accepted another answer because I hate migrations and it work :) – Lajdák Marek May 01 '19 at 13:59
  • 1
    It takes a little getting used to, but I cant imagine doing without migrations. Much, much more predictable what happens and if something goes wrong, it's easily backtraceable – Martijn May 01 '19 at 14:19
1

JSON Type is an unknown type for your MariaDB database version (cf type documentation). Doctrine creates a bad migration script, because it didn't know which version you're using.

Configure server_version in config/packages/doctrine.yml to:

doctrine:
dbal:
    # configure these for your database server
    driver: 'pdo_mysql'
    server_version: 'XXXX'
    ...

Replace X by your version, prefixed by mariadb- as mentioned in documentation. So DoctrineBundle will know that JSON is not supported and will replace by another type.

Alexandre Tranchant
  • 4,426
  • 4
  • 43
  • 70