MySQL / MariaDB not accepting JSON Format? Can not create Database

前端 未结 3 1287
别跟我提以往
别跟我提以往 2020-12-22 04:23

I am currently using XAMPP/Apache with MariaDB on phpmyadmin. I am trying to create a table based on my code using Doctrine and therefore Annotations for validating a form.

相关标签:
3条回答
  • 2020-12-22 05:09

    First check your mariadb version. Version 10.1 doesn't support JSON datatype and support for version 10.2 is incomplete.

    A workaround is to the version in doctrine.yaml file to

    server_version: '5.6'

    then regenerate the getters and setters with

    php bin/console make:entity --regenerate

    then generate the migration file with

    php bin/console make:migration

    this will generate a migration file with datatype set to LONGTEXT.

    Afterwards, in the src/Migrations open each file in there and check for any migration file with JSON as datatype and delete all migration with such datatype. Remember, if you don't delete these files, the next command iterates with each file persisting them to database one by one starting with the old one. If such file exist it will trigger the error again.

    Lastly, run

    php bin/console doctrine:migrations:migrate

    which will persist all the migrations to database accordingly.

    0 讨论(0)
  • 2020-12-22 05:10

    Based on your comments, it seems that Doctrine thinks it can use features that are not available on your version of mariadb.

    If you tell doctrine which version you are using, it will select the correct datatype for that column, in this case probably LONGTEXT or something similar.

    Depending on what you are using, it would look something like (using a yaml file in symfony for example):

    doctrine:
        dbal:
            server_version: '10.1'
    

    Note that you would need to re-generate your migrations.

    Like I mentioned in my comment, personally I would normalize the database and use a different table to link the pizza's to the ingredients to make searching and filtering easier.

    0 讨论(0)
  • 2020-12-22 05:25

    Had the same issue and i found this workaround:

    In Doctrine.yaml found out that the server_version was higher than my MariaDB version, so I corrected that in this line:

       doctrine:
            dbal:
                server_version: '5.5'
    

    I did not work until I manually erased the migrations i already did. You can found them in src/Migrations.

    Then run again:

     php bin/console make:migration
     php bin/console doctrine:migrations:migrate
    

    And that did the work, hope it helps.

    0 讨论(0)
提交回复
热议问题