简体   繁体   中英

How to resolve SQLSTATE[42000]: Syntax error or access violation: 1064

I have two entities, Match and Team, problem is in mapping (i guess), i am not looking for someone to give me solution to this problem, just give me some hint where should i look in documentation. For some reason i got stuck on this and can't find solution.. I will provide code of my two entities. Match.php

/**
 * @var
 * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Team", inversedBy="matchOne")
 * @ORM\JoinColumn(name="team_one_id", referencedColumnName="id")
 */
protected $teamOne;

/**
 * @var
 * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Team", inversedBy="matchTwo")
 * @ORM\JoinColumn(name="team_two_id", referencedColumnName="id")
 */
protected $teamTwo;

Team.php

/**
 * @var
 * @ORM\OneToMany(targetEntity="AppBundle\Entity\Match", mappedBy="teamOne")
 */
protected $matchOne;

/**
 * @var
 * @ORM\OneToMany(targetEntity="AppBundle\Entity\Match", mappedBy="teamTwo")
 */
protected $matchTwo;

Problem is in my form type when i query for match, here is part of code

->add('match', EntityType::class, [
        'class' => 'AppBundle:Match',
        'choice_label' => 'getMatch',
        ] )

And getMatch function

public function getMatch() {
    return $this->getTeamOne()->getName() . ' - ' . $this->getTeamTwo()->getName();
}

Form type is for creating new bet, obviously i want to show matches (team names, example: Chelsea - Liverpool) in drop down and write id of that match to bet entity.

Problem was in table name. Match is reserved word in MySQL. So everyone who experience same or similar problem please first check if your table names might be reserved word. I lost one whole day on this and every time i have some problem like this it is something stupid like this...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM