Symfony2抛出学说异常“检查与您的MySQL服务器版本对应的手册,以便在'group'附近使用正确的语法”

I'm working on a symfony project, I tried to add a data to database using entity but I got an Doctrine sql error?!!!! so any help is appritiated in advanced

I made an entity myselft which is :

/**
 * @ORM\Table(name="u001_user_group")
 * @ORM\Entity
 */
 class UserGroup 
 {       
    /**
     * @var integer
     *
     * @ORM\Column(name="group", type="integer", length=20, nullable=false)
     */
    private $group;

    public function setGroup($group)
    {
        $this->group = $group;

        return $this;
    }

    public function getGroup()
    {
        return $this->group;
    }
}       

And when I try to add something like this:

$UserGroup= new UserGroup();
            $UserGroup->setUser($registerAction->getId());
            $UserGroup->setGroup(4);
            $em->persist($UserGroup);
            $em->flush();

it give me this error:

An exception occurred while executing 'INSERT INTO u001_user_group (user, group) VALUES (?, ?)' with params [20, 4]:

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 'group) VALUES (20, 4)' at line 1

What @nifr said.

Just to add, if you absolutely need to use group you can use backticks to escape it like so:

/**
 * @var integer
 *
 * @ORM\Column(name="`group`", type="integer", length=20, nullable=false)
 */
private $group;

But generally speaking it's good practice to avoid reserved words.

group is a reserved keyword in MySQL.

Change the column name to resolve this issue.