MySQL/MariaDB不接受JSON格式?无法创建数据库 [英] MySQL / MariaDB not accepting JSON Format? Can not create Database

查看:662
本文介绍了MySQL/MariaDB不接受JSON格式?无法创建数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在phpmyadmin上将XAMPP/Apache与MariaDB一起使用. 我正在尝试使用Doctrine基于代码创建表,并因此基于验证表单创建批注.我只想将表单中输入的值存储在数据库中. 在另一个示例中,它工作得很好.

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. I simply want to store the entered values from the form in the database. In another example this worked perfectly fine.

但是现在我有一个复选框字段",我猜这在创建数据库时会引起某种麻烦.

But now i am having a "Checkbox field" that i guess is causing some kind of trouble when creating the database.

我正在控制台中使用这些命令:

I am using those commands in the console:

php bin/console make:migration

之后:

php bin/console doctrine:migrations:migrate

调用第二个=当我尝试在数据库中创建表时,出现以下错误:

When calling the 2nd one = when i try to create the table in my database i get the following errors:

Migration 20181121103017 failed during Execution. 
Error An exception occurred while executing 'CREATE TABLE pizza (id INT 
AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, address VARCHAR(255) NOT NULL
phone VARCHAR(255) NOT NULL, email VARCHAR(255) NOT NULL, 
size INT NOT NULL, ingredient JSON NOT NULL COMMENT '(DC2Type:json_array)', delivery INT NOT NULL, 
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 COMMENT '(DC2Type:json_
array)', delivery INT NOT NULL, PRIMARY KEY' at line 1

我现在真的不知道我在做什么错.

I am really not knowing what i am doing wrong at this point.

这些是我在"Pizza.php"文件中的注释.

These are my annotations i have in my "Pizza.php" File.

// ------------------

/**
 * @Assert\NotBlank(
 *     message = "E-Mail Address required"
 * )
 * @Assert\Email(
 *     message = "The email '{{ value }}' is not a valid email."
 * )
 * @Assert\Length(min="2", max="255")
 * @ORM\Column(type="string", length=255)
 */

protected $email;

// ------------------

/**
 * @Assert\Range(min=0, max=3)
 * @ORM\Column(type="integer")
 */

protected $size;

// ------------------

/**
 *@Assert\NotBlank(
 *     message = "Choose at least 1 ingredient!"
 * )
 * @ORM\Column(type="array")
 */

protected $ingredient;

// ------------------

/**
 * @Assert\NotBlank(
 *     message = "Choose a delivery option!"
 * )
 * @Assert\Range(min=0, max=1)
 * @ORM\Column(type="integer")
 */

protected $delivery;

表单本身运行正常,验证确实按照我的意图进行.

The form itself is working perfectly fine, the validations do work the way i intended.

我到底在做什么错?

如果您需要我的"Pizza.php"(实体类)或我在其中进行路由的控制器文件中的更多代码,请告诉我.

If you need any more code from my "Pizza.php" (Entity Class) or my Controller File where i did my routing please let me know.

我非常感谢您的帮助!

I am grateful for any help!

推荐答案

根据您的评论,Doctrine似乎认为它可以使用在您的mariadb版本上不可用的功能.

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

如果您告诉主义您使用的是哪个版本,它将为该列选择正确的数据类型,在这种情况下,可能是LONGTEXT或类似的内容.

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.

根据您所使用的内容,它看起来像(例如在symfony中使用yaml文件):

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.

这篇关于MySQL/MariaDB不接受JSON格式?无法创建数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆