Symfony 4 after generating user via make:user schema update crashed - symfony

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

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

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.

Related

Cannot set the number of password retries in MariaDB

I did the following to set password restrictions for my users on MariaDB.
ALTER USER 'User Name' FAILED_LOGIN_ATTEMPTS 3 PASSWORD_LOCK_TIME 3;
But I get the following error and cannot do it.
Why is this?
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'FAILED_LOGIN_ATTEMPTS 3 PASSWORD_LOCK_TIME 3' at line 1
As mentioned in the comments, MariaDB does not have this feature.

How to make MariaDB log in JSON format?

In MySQL you can make logging appear in JSON format by installing component_log_sink_json component and enabling this component:
INSTALL COMPONENT 'file://component_log_sink_json';
SET PERSIST log_error_services = 'log_filter_internal; log_sink_json';
Source: https://dev.mysql.com/doc/refman/8.0/en/error-log-json.html
But this does not work in MariaDB:
MariaDB > INSTALL COMPONENT 'file://component_log_sink_json';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COMPONENT 'file://component_log_sink_json'' at line 1
MariaDB > SET log_error_services = 'log_filter_internal; log_sink_json';
ERROR 1193 (HY000): Unknown system variable 'log_error_services'
How can I make MariaDB log in JSON format?

Doctrine(Symfony4) is storing data as invalid HEX values

When I was about to deploy my Symfony4 app in ubuntu 18 php7.1-fpm + apache I execute some commands to load default data and some fixtures. The problem is that always receive SQLSTATE[22021]: Character not in repertoire: 7 ERROR: invalid byte sequence for encoding "UTF8": 0xcd 0x73 In the entities I noticed that are the fields which are mapped as array, json, or simple_array.
Here is an example of one of those fields value:
\x65\x6d\x70\x72\x65\x73\x61\x20\x64\x65\x20\x6
1\x73\x65\x67\x75\x72\x61\x6d\x69\x65\x6e\x74\x6f\x20\x6c\x6f\x67\xcd\x73\x74\x69\x63\x6f\x20\x61\x6c\x20\x74\x61\x62\x61\x63\x6f
That is the value for an array of string.
The database config is setted to UTF-8 also the php.ini configuration, the database server is created also using UTF-8.
How can I fix this? I've created the database several times but the same results remains.
Thanks in advance!!
UPDATE
When I repeat the process on Windows none of this happens...
UPDATE
Here the complete crash log
[2019-10-08 15:21:26] doctrine.DEBUG: INSERT INTO ext_log_entries (id, action, logged_at, object_id, object_class, version, data, username) VALUES (?, ?, ?, ?, ?, ?, ?, ?) {"1":2042,"2":"create","3":"2019-10-08 15:21:24","4":2042,"5":"App\\Entity\\SeaShipment","6":1,"7":{"manifest":"0323/2019","dmNumber":null,"arrivedAt":"2019-09-16 23:00:00","companyName":"MAQUIMPORT","agencyName":"MINAGRI","contractNumber":null,"merchandiseDescription":null,"countryName":null,"dmNumberAt":null,"etaAt":null,"funderName":null,"customerName":null,"empoweredName":null,"buyerName":null,"docsReceivedAt":null,"originalDocsReceivedAt":null,"billingDeliveredAt":null,"funderBilling":null,"deliveredCustomerAt":null,"isUpdatable":null,"createdFromIp":null,"lastUpdatedFromIp":null,"createdBy":null,"lastUpdatedBy":null,"createdAt":"2019-10-08 15:21:20","lastUpdatedAt":"2019-10-08 15:21:20","deletedAt":null,"seaShipmentType":null,"bl":"2019-M-001147","destinationDock":"TCM","isReleasedHouse":true,"isReleasedMaster":true,"isLocked":false,"isEnabled":true,"daysWithoutDm":0,"daysInTcm":3,"location":"B06","weight":8562,"yard":null,"cabotage":null,"transferedAt":"2019-09-16 14:25:00","transferedTo":"(binary value)","containerNumber":"MAGU5169507","containerType":"HC","containerDimention":40,"lastMarielReportAt":"2019-09-19 23:00:00","shippingCompanyName":"NIRINT","isActive":true,"shipName":null,"journey":null,"originDock":null,"blAt":null,"correspondentName":null,"forwarderName":null,"downloadUngroupAt":null,"beDeliveredAt":null,"packageQuantity":null,"shippingCompany":{"id":26}},"8":null} []
For other similar data or transactions before this one the problem is not happening
Can it be that your database doesn't accept cyrillyc/arabic etc alphabets ?
If yes that may help (if you use mysql):
Add to file etc/mysql/my.cnf:
[mysqld]
collation-server = utf8mb4_bin
init-connect='SET NAMES utf8mb4'
character-set-server = utf8mb4
skip-character-set-client-handshake
[client]
default-character-set = utf8mb4
[mysql]
default-character-set = utf8mb4
After that :
sudo service mysql restart
then drop database and create it from scratch.

ViciDial: MyISAM Specified key was too long; max key length is 1000 bytes

I have installed MariaDB in a Ubuntu 14.04 and trying to run some scripts that the main solution provides (ViciDial). When I try to execute the Sql file, it gives an error in the following CREATE TABLE statement:
CREATE TABLE www_phrases (
phrase_id INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY NOT NULL,
phrase_text VARCHAR(10000) default '',
php_filename VARCHAR(255) NOT NULL,
php_directory VARCHAR(255) default '',
source VARCHAR(20) default '',
insert_date DATETIME,
index (phrase_text)
) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_unicode_ci;
The error is:
ERROR 1071 (42000) at line 3348: Specified key was too long; max key length is 1000 bytes
MariaDB status:
MariaDB [DialerDB]> status;
--------------
mysql Ver 15.1 Distrib 10.0.38-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2
Connection id: 53
Current database: DialerDB
Current user: root#localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server: MariaDB
Server version: 10.0.38-MariaDB-0ubuntu0.16.04.1 Ubuntu 16.04
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8mb4
Db characterset: utf8mb4
Client characterset: utf8mb4
Conn. characterset: utf8mb4
UNIX socket: /var/run/mysqld/mysqld.sock
Uptime: 1 hour 15 min 49 sec
As far as I understand the limit in MyISAM is 1000, and in newer versions is around 3200, so if the varchar is 10000 this is an error, correct?
But this software is installed correctly if done via installer (an ISO image) and the DB tables are the same...so there must be some config limiting my MariaDB to do this.
Any idea?
If that column has "text" in it, suggest looking into a FULLTEXT index; it will search for words quite efficiently.
A compilation of the limits is here; 10K won't work for a simple index.
(Meanwhile, you should move from MyISAM to InnoDB.)

Syntax error or access violation: 1064 You have an error in your SQL In symfony

When i run comand php bin/console doctrine:migration:migrate i got this error I don't know where is come from.
command line error :
In AbstractMySQLDriver.php line 99:
An exception occurred while executing 'CREATE TABLE user (id INT AUTO_INCREMENT NOT NULL, email VARCHAR(180) NOT NU
LL, 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 MariaDB 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 PDOConnection.php line 109:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that
corresponds to your MariaDB 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 PDOConnection.php line 107:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that
corresponds to your MariaDB server version for the right syntax to use near 'JSON NOT NULL, password VARCHAR(255)
NOT NULL, UNIQUE INDEX UNIQ_8D93D649E7927C7' at line 1
My env
my env
Andrei is right. You either have to upgrade your database or (much easier) config your symfony to use the lower Version of MySQL.
config/packages/doctrine.yaml
doctrine:
dbal:
# configure these for your database server
driver: 'pdo_mysql'
server_version: '5.6'
here you can find a table with the compatibilitys of MySQL and MariaDB.
Update your MySQL's version to MySQL 5.7.
Because your current version does not support MySQL 5.7's JSON objects.
In this case you can simply paste this code in config/packages/doctrine.yaml :
doctrine:
dbal:
# configure these for your database server
driver: 'pdo_mysql'
server_version: '5.5'
Please note that the version information can conflict with the one defined in the database URL
If you added the server version information to the doctrine.yaml and the problem persisted, try checking "serverVersion" at the end if your database URL and set it to 5.6 or the compatible vresion you found

Resources