User migration fails









up vote
0
down vote

favorite












1) I created User Class with make:user command:



Console image



2) I generated migration file with make:migration command.



3) Here is the up() function in migration file:



 final class Version20181110133851 extends AbstractMigration

public function up(Schema $schema) : void


$this->abortIf($this->connection->getDatabasePlatform()->getName() !==
'mysql', 'Migration can only be executed safely on 'mysql'.');

$this->addSql('ALTER TABLE user ADD email VARCHAR(180) NOT NULL, ADD roles JSON NOT NULL, CHANGE id id INT AUTO_INCREMENT NOT NULL, ADD PRIMARY KEY (id)');
$this->addSql('CREATE UNIQUE INDEX UNIQ_8D93D649E7927C74 ON user (email)');

...



4) This is what happens when I try to migrate to data base with doctrine:migration:migrate command



Image showing the error



and here is the content of the error:



 -> ALTER TABLE user ADD email VARCHAR(180) NOT NULL, ADD roles JSON NOT 
NULL, CHANGE id id INT AUTO_INCREMENT NOT NULL, ADD PRIMARY KEY (id)
Migration 20181110133851 failed during Execution. Error An exception
occurred while executing 'ALTER TABLE user ADD email VARCHAR(180) NOT
NULL, ADD roles JSON NOT NULL, CHANGE id id INT AUTO_INCREMENT NOT NULL,
ADD PRIMARY KEY (id)':

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, CHANGE id
id INT AUTO_INCREMENT NOT NULL, ADD PRIMARY KEY (id)' at line 1

In AbstractMySQLDriver.php line 99:

An exception occurred while executing 'ALTER TABLE user ADD email
VARCHAR(180) NOT NULL, ADD roles JSON NOT NULL, CHANGE id id INT
AUTO_INCREMENT NOT NULL, ADD PRI
MARY KEY (id)':

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, CHANGE id id INT
AUTO_INCREMENT NOT NULL, ADD PRIMARY KEY (id)' 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, CHANGE id id INT
AUTO_INCREMENT NOT NULL, ADD PRIMARY KEY (id)' 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, CHANGE id id INT
AUTO_INCREMENT NOT NULL, ADD PRIMARY KEY (id)' at line 1


5) I've been trying to solve it for hours, but I am still a newbie and I don't think I am going to solve it myself.



6) My question: Where is the SYNTAX ERROR?










share|improve this question

















  • 1




    What is your mysql version? JSON fields are only available for 5.7+
    – Padam87
    Nov 10 at 15:12











  • C:xamppmysqlbin>mysql --version mysql Ver 15.1 Distrib 10.1.36-MariaDB, for Win32 (AMD64)
    – Maciek
    Nov 10 at 17:21














up vote
0
down vote

favorite












1) I created User Class with make:user command:



Console image



2) I generated migration file with make:migration command.



3) Here is the up() function in migration file:



 final class Version20181110133851 extends AbstractMigration

public function up(Schema $schema) : void


$this->abortIf($this->connection->getDatabasePlatform()->getName() !==
'mysql', 'Migration can only be executed safely on 'mysql'.');

$this->addSql('ALTER TABLE user ADD email VARCHAR(180) NOT NULL, ADD roles JSON NOT NULL, CHANGE id id INT AUTO_INCREMENT NOT NULL, ADD PRIMARY KEY (id)');
$this->addSql('CREATE UNIQUE INDEX UNIQ_8D93D649E7927C74 ON user (email)');

...



4) This is what happens when I try to migrate to data base with doctrine:migration:migrate command



Image showing the error



and here is the content of the error:



 -> ALTER TABLE user ADD email VARCHAR(180) NOT NULL, ADD roles JSON NOT 
NULL, CHANGE id id INT AUTO_INCREMENT NOT NULL, ADD PRIMARY KEY (id)
Migration 20181110133851 failed during Execution. Error An exception
occurred while executing 'ALTER TABLE user ADD email VARCHAR(180) NOT
NULL, ADD roles JSON NOT NULL, CHANGE id id INT AUTO_INCREMENT NOT NULL,
ADD PRIMARY KEY (id)':

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, CHANGE id
id INT AUTO_INCREMENT NOT NULL, ADD PRIMARY KEY (id)' at line 1

In AbstractMySQLDriver.php line 99:

An exception occurred while executing 'ALTER TABLE user ADD email
VARCHAR(180) NOT NULL, ADD roles JSON NOT NULL, CHANGE id id INT
AUTO_INCREMENT NOT NULL, ADD PRI
MARY KEY (id)':

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, CHANGE id id INT
AUTO_INCREMENT NOT NULL, ADD PRIMARY KEY (id)' 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, CHANGE id id INT
AUTO_INCREMENT NOT NULL, ADD PRIMARY KEY (id)' 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, CHANGE id id INT
AUTO_INCREMENT NOT NULL, ADD PRIMARY KEY (id)' at line 1


5) I've been trying to solve it for hours, but I am still a newbie and I don't think I am going to solve it myself.



6) My question: Where is the SYNTAX ERROR?










share|improve this question

















  • 1




    What is your mysql version? JSON fields are only available for 5.7+
    – Padam87
    Nov 10 at 15:12











  • C:xamppmysqlbin>mysql --version mysql Ver 15.1 Distrib 10.1.36-MariaDB, for Win32 (AMD64)
    – Maciek
    Nov 10 at 17:21












up vote
0
down vote

favorite









up vote
0
down vote

favorite











1) I created User Class with make:user command:



Console image



2) I generated migration file with make:migration command.



3) Here is the up() function in migration file:



 final class Version20181110133851 extends AbstractMigration

public function up(Schema $schema) : void


$this->abortIf($this->connection->getDatabasePlatform()->getName() !==
'mysql', 'Migration can only be executed safely on 'mysql'.');

$this->addSql('ALTER TABLE user ADD email VARCHAR(180) NOT NULL, ADD roles JSON NOT NULL, CHANGE id id INT AUTO_INCREMENT NOT NULL, ADD PRIMARY KEY (id)');
$this->addSql('CREATE UNIQUE INDEX UNIQ_8D93D649E7927C74 ON user (email)');

...



4) This is what happens when I try to migrate to data base with doctrine:migration:migrate command



Image showing the error



and here is the content of the error:



 -> ALTER TABLE user ADD email VARCHAR(180) NOT NULL, ADD roles JSON NOT 
NULL, CHANGE id id INT AUTO_INCREMENT NOT NULL, ADD PRIMARY KEY (id)
Migration 20181110133851 failed during Execution. Error An exception
occurred while executing 'ALTER TABLE user ADD email VARCHAR(180) NOT
NULL, ADD roles JSON NOT NULL, CHANGE id id INT AUTO_INCREMENT NOT NULL,
ADD PRIMARY KEY (id)':

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, CHANGE id
id INT AUTO_INCREMENT NOT NULL, ADD PRIMARY KEY (id)' at line 1

In AbstractMySQLDriver.php line 99:

An exception occurred while executing 'ALTER TABLE user ADD email
VARCHAR(180) NOT NULL, ADD roles JSON NOT NULL, CHANGE id id INT
AUTO_INCREMENT NOT NULL, ADD PRI
MARY KEY (id)':

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, CHANGE id id INT
AUTO_INCREMENT NOT NULL, ADD PRIMARY KEY (id)' 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, CHANGE id id INT
AUTO_INCREMENT NOT NULL, ADD PRIMARY KEY (id)' 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, CHANGE id id INT
AUTO_INCREMENT NOT NULL, ADD PRIMARY KEY (id)' at line 1


5) I've been trying to solve it for hours, but I am still a newbie and I don't think I am going to solve it myself.



6) My question: Where is the SYNTAX ERROR?










share|improve this question













1) I created User Class with make:user command:



Console image



2) I generated migration file with make:migration command.



3) Here is the up() function in migration file:



 final class Version20181110133851 extends AbstractMigration

public function up(Schema $schema) : void


$this->abortIf($this->connection->getDatabasePlatform()->getName() !==
'mysql', 'Migration can only be executed safely on 'mysql'.');

$this->addSql('ALTER TABLE user ADD email VARCHAR(180) NOT NULL, ADD roles JSON NOT NULL, CHANGE id id INT AUTO_INCREMENT NOT NULL, ADD PRIMARY KEY (id)');
$this->addSql('CREATE UNIQUE INDEX UNIQ_8D93D649E7927C74 ON user (email)');

...



4) This is what happens when I try to migrate to data base with doctrine:migration:migrate command



Image showing the error



and here is the content of the error:



 -> ALTER TABLE user ADD email VARCHAR(180) NOT NULL, ADD roles JSON NOT 
NULL, CHANGE id id INT AUTO_INCREMENT NOT NULL, ADD PRIMARY KEY (id)
Migration 20181110133851 failed during Execution. Error An exception
occurred while executing 'ALTER TABLE user ADD email VARCHAR(180) NOT
NULL, ADD roles JSON NOT NULL, CHANGE id id INT AUTO_INCREMENT NOT NULL,
ADD PRIMARY KEY (id)':

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, CHANGE id
id INT AUTO_INCREMENT NOT NULL, ADD PRIMARY KEY (id)' at line 1

In AbstractMySQLDriver.php line 99:

An exception occurred while executing 'ALTER TABLE user ADD email
VARCHAR(180) NOT NULL, ADD roles JSON NOT NULL, CHANGE id id INT
AUTO_INCREMENT NOT NULL, ADD PRI
MARY KEY (id)':

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, CHANGE id id INT
AUTO_INCREMENT NOT NULL, ADD PRIMARY KEY (id)' 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, CHANGE id id INT
AUTO_INCREMENT NOT NULL, ADD PRIMARY KEY (id)' 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, CHANGE id id INT
AUTO_INCREMENT NOT NULL, ADD PRIMARY KEY (id)' at line 1


5) I've been trying to solve it for hours, but I am still a newbie and I don't think I am going to solve it myself.



6) My question: Where is the SYNTAX ERROR?







php symfony security doctrine






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 10 at 13:57









Maciek

43




43







  • 1




    What is your mysql version? JSON fields are only available for 5.7+
    – Padam87
    Nov 10 at 15:12











  • C:xamppmysqlbin>mysql --version mysql Ver 15.1 Distrib 10.1.36-MariaDB, for Win32 (AMD64)
    – Maciek
    Nov 10 at 17:21












  • 1




    What is your mysql version? JSON fields are only available for 5.7+
    – Padam87
    Nov 10 at 15:12











  • C:xamppmysqlbin>mysql --version mysql Ver 15.1 Distrib 10.1.36-MariaDB, for Win32 (AMD64)
    – Maciek
    Nov 10 at 17:21







1




1




What is your mysql version? JSON fields are only available for 5.7+
– Padam87
Nov 10 at 15:12





What is your mysql version? JSON fields are only available for 5.7+
– Padam87
Nov 10 at 15:12













C:xamppmysqlbin>mysql --version mysql Ver 15.1 Distrib 10.1.36-MariaDB, for Win32 (AMD64)
– Maciek
Nov 10 at 17:21




C:xamppmysqlbin>mysql --version mysql Ver 15.1 Distrib 10.1.36-MariaDB, for Win32 (AMD64)
– Maciek
Nov 10 at 17:21












2 Answers
2






active

oldest

votes

















up vote
0
down vote



accepted










As @Padam87 said, MariaDB does not support the native JSON type. If you can't upgrade your database for whatever reason but don't want to change the column type, just define the database version in the Doctrine properties and let Doctrine handle the conversion for you.



doctrine.yaml:



doctrine:
dbal:
server_version: '10.1.36-MariaDB'


This will add a comment in the table definition which Doctrine will use later to encode/decode the values.






share|improve this answer



























    up vote
    1
    down vote













    Mariadb 10.1 does not support the native json type, so you will have to use another type. Change your column definition, delete this migration, and generate a new one.



    Alternatively, you can upgrade. Mariadb starts supporting the json type from 10.2.7 and up. https://mariadb.com/kb/en/library/json-data-type/






    share|improve this answer




















    • yep, it helped. Thanks. Ave Juve.
      – Maciek
      Nov 10 at 19:01











    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53239688%2fuser-migration-fails%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote



    accepted










    As @Padam87 said, MariaDB does not support the native JSON type. If you can't upgrade your database for whatever reason but don't want to change the column type, just define the database version in the Doctrine properties and let Doctrine handle the conversion for you.



    doctrine.yaml:



    doctrine:
    dbal:
    server_version: '10.1.36-MariaDB'


    This will add a comment in the table definition which Doctrine will use later to encode/decode the values.






    share|improve this answer
























      up vote
      0
      down vote



      accepted










      As @Padam87 said, MariaDB does not support the native JSON type. If you can't upgrade your database for whatever reason but don't want to change the column type, just define the database version in the Doctrine properties and let Doctrine handle the conversion for you.



      doctrine.yaml:



      doctrine:
      dbal:
      server_version: '10.1.36-MariaDB'


      This will add a comment in the table definition which Doctrine will use later to encode/decode the values.






      share|improve this answer






















        up vote
        0
        down vote



        accepted







        up vote
        0
        down vote



        accepted






        As @Padam87 said, MariaDB does not support the native JSON type. If you can't upgrade your database for whatever reason but don't want to change the column type, just define the database version in the Doctrine properties and let Doctrine handle the conversion for you.



        doctrine.yaml:



        doctrine:
        dbal:
        server_version: '10.1.36-MariaDB'


        This will add a comment in the table definition which Doctrine will use later to encode/decode the values.






        share|improve this answer












        As @Padam87 said, MariaDB does not support the native JSON type. If you can't upgrade your database for whatever reason but don't want to change the column type, just define the database version in the Doctrine properties and let Doctrine handle the conversion for you.



        doctrine.yaml:



        doctrine:
        dbal:
        server_version: '10.1.36-MariaDB'


        This will add a comment in the table definition which Doctrine will use later to encode/decode the values.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 10 at 20:50









        Arne

        684




        684






















            up vote
            1
            down vote













            Mariadb 10.1 does not support the native json type, so you will have to use another type. Change your column definition, delete this migration, and generate a new one.



            Alternatively, you can upgrade. Mariadb starts supporting the json type from 10.2.7 and up. https://mariadb.com/kb/en/library/json-data-type/






            share|improve this answer




















            • yep, it helped. Thanks. Ave Juve.
              – Maciek
              Nov 10 at 19:01















            up vote
            1
            down vote













            Mariadb 10.1 does not support the native json type, so you will have to use another type. Change your column definition, delete this migration, and generate a new one.



            Alternatively, you can upgrade. Mariadb starts supporting the json type from 10.2.7 and up. https://mariadb.com/kb/en/library/json-data-type/






            share|improve this answer




















            • yep, it helped. Thanks. Ave Juve.
              – Maciek
              Nov 10 at 19:01













            up vote
            1
            down vote










            up vote
            1
            down vote









            Mariadb 10.1 does not support the native json type, so you will have to use another type. Change your column definition, delete this migration, and generate a new one.



            Alternatively, you can upgrade. Mariadb starts supporting the json type from 10.2.7 and up. https://mariadb.com/kb/en/library/json-data-type/






            share|improve this answer












            Mariadb 10.1 does not support the native json type, so you will have to use another type. Change your column definition, delete this migration, and generate a new one.



            Alternatively, you can upgrade. Mariadb starts supporting the json type from 10.2.7 and up. https://mariadb.com/kb/en/library/json-data-type/







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 10 at 18:20









            Padam87

            88857




            88857











            • yep, it helped. Thanks. Ave Juve.
              – Maciek
              Nov 10 at 19:01

















            • yep, it helped. Thanks. Ave Juve.
              – Maciek
              Nov 10 at 19:01
















            yep, it helped. Thanks. Ave Juve.
            – Maciek
            Nov 10 at 19:01





            yep, it helped. Thanks. Ave Juve.
            – Maciek
            Nov 10 at 19:01


















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53239688%2fuser-migration-fails%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kleinkühnau

            Makov (Slowakei)

            Deutsches Schauspielhaus