0
votes

I am learning symfony and I am trying to apply what is explained in the "Creating the Database Tables Schema" section of the Doctrine chapter. I run the following command:

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

I get errors:

[Doctrine\DBAL\Exception\SyntaxErrorException]
An exception occurred while executing 'CREATE TABLE vente\produit (id INT AUTO_INCREMENT NOT NULL, nom VARCHAR(28) NOT NULL, prix DOUBLE PRECIS ION DEFAULT NULL, Descro LONGTEXT NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_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 '\produit (id INT AUTO_INCREMENT NOT NULL, nom VARCHAR(28) NOT NULL, prix DOUBLE ' at line 1

                                                                                                                                                  [Doctrine\DBAL\Driver\PDOException]                                   

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 '\produit (id INT AUTO_INCREMENT NOT NULL, nom VARCHAR(28) NOT NULL, prix DOUBLE ' at line 1

                                                                                                                                                  [PDOException]                                                        

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 '\produit (id INT AUTO_INCREMENT NOT NULL, nom VARCHAR(28) NOT NULL, prix DOUBLE ' at line 1

                                                                         .

If I run the dump directly from the mysql> prompt, it creates the table properly My entity is this one:

<?php

namespace AppBundle\Entity\Vente;

use Doctrine\ORM\Mapping as ORM;

/**
 * Produit
 *
 * @ORM\Table(name="vente\produit")
 * @ORM\Entity(repositoryClass="AppBundle\Repository\Vente\ProduitRepository")
 */
class Produit
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var string
     *
     * @ORM\Column(name="nom", type="string", length=28)
     */
    private $nom;

    /**
     * @var float
     *
     * @ORM\Column(name="prix", type="float", nullable=true)
     */
    private $prix;

    /**
     * @var string
     *
     * @ORM\Column(name="Descro", type="text")
     */
    private $descro;


    /**
     * Get id
     *
     * @return int
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set nom
     *
     * @param string $nom
     *
     * @return Produit
     */
    public function setNom($nom)
    {
        $this->nom = $nom;

        return $this;
    }

    /**
     * Get nom
     *
     * @return string
     */
    public function getNom()
    {
        return $this->nom;
    }

    /**
     * Set prix
     *
     * @param float $prix
     *
     * @return Produit
     */
    public function setPrix($prix)
    {
        $this->prix = $prix;

        return $this;
    }

    /**
     * Get prix
     *
     * @return float
     */
    public function getPrix()
    {
        return $this->prix;
    }

    /**
     * Set descro
     *
     * @param string $descro
     *
     * @return Produit
     */
    public function setDescro($descro)
    {
        $this->descro = $descro;

        return $this;
    }

    /**
     * Get descro
     *
     * @return string
     */
    public function getDescro()
    {
        return $this->descro;
    }
}
1

1 Answers

0
votes

In fact the trouble was due to the fact that I put the entity in a subfolder "Vente" of "AppBundle/Entity". It produced a strange table name Vente/Produit. Putting it directly in Entity solved the trouble.