简体   繁体   中英

Can't get my Entity using find method or api platform?

I am facing a weird problem, so the problem is that I created an Entity called Option using symfony command lines after adding my fields' name and type and so forth :

php bin/console make:migration

php bin/console doctrine:migrations:migrate

And ad I mentionned above, I am using api platform, so in order to get all my options, it will take me just to type :

localhost/api/options

But instead of getting results, I get an error talking about something bad t=in the SQL syntax, which I am surely not responsible for because it is generated itself.

So I tried to get those options using the traditionnal symfony method find and again the same error, I tried to get just a signle one using findOneBy and the same, so the error is this :

An exception occurred while executing 'SELECT t0.id AS id_1, t0.label AS label_2 FROM option t0 WHERE t0.id = ?'with params [53]:

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'option t0 WHERE t0.id = 53' at line 1

I surely don't know how to solve this, But I think that option is a reseved word but I am not sure about that.

Of course I dont think that there is any problem with code but some people ask for it even if it is unnecessary, but here is a simple code that caused the same problem in my controller :

$OptionManager = $this->getDoctrine()->getRepository(Option::class);
$options = $OptionManager->find(11);

Any help would be much appreciated

SQLSTATE[42000]: Syntax error or access violation: 1064 is indicating that option is a reserved word in MySQL. [sic]

In Doctrine, reserved words must be escaped with back-ticks in your entity specifications.

Sometimes it is necessary to quote a column or table name because of reserved word conflicts. Doctrine does not quote identifiers automatically. [sic]

/**
 * @ORM\Entity
 * @ORM\Table(name="`option`")
 */
class Option
{
    //...
}

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