php - 我的 Symfony2 应用程序出现语法错误或访问冲突

标签 php mysql forms symfony doctrine-orm

我无法通过表单创建我的实体,因为我遇到了这个错误:

CRITICAL - Uncaught PHP Exception Doctrine\DBAL\DBALException: "An exception occurred while executing 'INSERT INTO Task (title, misc, url, attachment, time_estimated, started_at, finished_at, default, deadline, task_priority_id, task_id, project_id, task_category_id, user_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)' with params ["Test", null, null, null, null, null, null, 0, null, 15, null, 2, 44, 5]: 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 'default, deadline, task_priority_id, task_id, project_id, task_category_id, user' at line 1" at C:\LanTools\xampp\htdocs\sf2_akimedia-crm\vendor\doctrine\dbal\lib\Doctrine\DBAL\DBALException.php line 91

这是我的任务实体:

use Doctrine\ORM\Mapping AS ORM;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * @ORM\Entity(repositoryClass="Lan\CrmBundle\Entity\TaskRepository")
 *
 */
class Task
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @ORM\Column(type="string", length=255, nullable=false)
     * @Assert\NotBlank()
     */
    private $title;

    /**
     * @ORM\Column(type="text", nullable=true)
     */
    private $misc;

    /**
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private $url;

    /**
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private $attachment;

    /**
     * @ORM\ManyToOne(targetEntity="Lan\CrmBundle\Entity\TaskPriority", inversedBy="tasks")
     * @ORM\JoinColumn(name="task_priority_id", referencedColumnName="id", nullable=false)
     */
    private $priority;

    /** 
     * @ORM\ManyToOne(targetEntity="Lan\CrmBundle\Entity\Task", inversedBy="tasks")
     * @ORM\JoinColumn(name="task_id", referencedColumnName="id")
     */
    private $task;

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

    /**
     * @ORM\Column(type="datetime", nullable=true)
     */
    private $started_at;

    /**
     * @ORM\Column(type="datetime", nullable=true)
     */
    private $finished_at;

    /**
     * @ORM\Column(type="boolean", nullable=true)
     */
    private $default;

    /** 
     * @ORM\OneToMany(targetEntity="Lan\CrmBundle\Entity\Task", mappedBy="task")
     */
    private $tasks;

    /**
     * @ORM\Column(type="date", nullable=true)
     */
    private $deadline;

    /**
     * @ORM\OneToMany(targetEntity="Lan\CrmBundle\Entity\Comment", mappedBy="task")
     */
    private $comments;

    /**
     * @ORM\OneToMany(targetEntity="Lan\CrmBundle\Entity\Account", mappedBy="task")
     */
    private $accounts;

    /**
     * @ORM\ManyToOne(targetEntity="Lan\CrmBundle\Entity\Project", inversedBy="tasks")
     * @ORM\JoinColumn(name="project_id", referencedColumnName="id", nullable=false)
     */
    private $project;

    /**
     * @ORM\ManyToOne(targetEntity="Lan\CrmBundle\Entity\TaskCategory", inversedBy="tasks")
     * @ORM\JoinColumn(name="task_category_id", referencedColumnName="id", nullable=false)
     */
    private $category;

    /**
     * @ORM\ManyToOne(targetEntity="Lan\SecurityBundle\Entity\User", inversedBy="tasks")
     * @ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=false)
     */
    private $user;

    /**
     *
     */
    private $products;

    /**
     * Constructor
     */
    public function __construct()
    {
        $this->comments = new \Doctrine\Common\Collections\ArrayCollection();
        $this->accounts = new \Doctrine\Common\Collections\ArrayCollection();
        $this->products = new \Doctrine\Common\Collections\ArrayCollection();
    }

    /**
     *
     */
    public function setStartedAtValue()
    {
        $this->started_at = new \DateTime();
    }

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

    /**
     * Set title
     *
     * @param string $title
     * @return Task
     */
    public function setTitle($title)
    {
        $this->title = $title;

        return $this;
    }

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

    /**
     * Set misc
     *
     * @param string $misc
     * @return Task
     */
    public function setMisc($misc)
    {
        $this->misc = $misc;

        return $this;
    }

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

    /**
     * Set url
     *
     * @param string $url
     * @return Task
     */
    public function setUrl($url)
    {
        $this->url = $url;

        return $this;
    }

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

    /**
     * Set attachment
     *
     * @param string $attachment
     * @return Task
     */
    public function setAttachment($attachment)
    {
        $this->attachment = $attachment;

        return $this;
    }

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

    /**
     * Set priority
     *
     * @param integer $priority
     * @return Task
     */
    public function setPriority($priority)
    {
        $this->priority = $priority;

        return $this;
    }

    /**
     * Get priority
     *
     * @return integer
     */
    public function getPriority()
    {
        return $this->priority;
    }

    /**
     * Set time_estimated
     *
     * @param float $timeEstimated
     * @return Task
     */
    public function setTimeEstimated($timeEstimated)
    {
        $this->time_estimated = $timeEstimated;

        return $this;
    }

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

    /**
     * Set started_at
     *
     * @param \DateTime $startedAt
     * @return Task
     */
    public function setStartedAt($startedAt)
    {
        $this->started_at = $startedAt;

        return $this;
    }

    /**
     * Get started_at
     *
     * @return \DateTime
     */
    public function getStartedAt()
    {
        return $this->started_at;
    }

    /**
     * Set finished_at
     *
     * @param \DateTime $finishedAt
     * @return Task
     */
    public function setFinishedAt($finishedAt)
    {
        $this->finished_at = $finishedAt;

        return $this;
    }

    /**
     * Get finished_at
     *
     * @return \DateTime
     */
    public function getFinishedAt()
    {
        return $this->finished_at;
    }

    /**
     * Set default
     *
     * @param boolean $default
     * @return Task
     */
    public function setDefault($default)
    {
        $this->default = $default;

        return $this;
    }

    /**
     * Get default
     *
     * @return boolean
     */
    public function getDefault()
    {
        return $this->default;
    }

    /**
     * Add comments
     *
     * @param \Lan\CrmBundle\Entity\Comment $comments
     * @return Task
     */
    public function addComment(\Lan\CrmBundle\Entity\Comment $comments)
    {
        $this->comments[] = $comments;

        return $this;
    }

    /**
     * Remove comments
     *
     * @param \Lan\CrmBundle\Entity\Comment $comments
     */
    public function removeComment(\Lan\CrmBundle\Entity\Comment $comments)
    {
        $this->comments->removeElement($comments);
    }

    /**
     * Get comments
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getComments()
    {
        return $this->comments;
    }

    /**
     * Add accounts
     *
     * @param \Lan\CrmBundle\Entity\Account $accounts
     * @return Task
     */
    public function addAccount(\Lan\CrmBundle\Entity\Account $accounts)
    {
        $this->accounts[] = $accounts;

        return $this;
    }

    /**
     * Remove accounts
     *
     * @param \Lan\CrmBundle\Entity\Account $accounts
     */
    public function removeAccount(\Lan\CrmBundle\Entity\Account $accounts)
    {
        $this->accounts->removeElement($accounts);
    }

    /**
     * Get accounts
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getAccounts()
    {
        return $this->accounts;
    }

    /**
     * Set project
     *
     * @param \Lan\CrmBundle\Entity\Project $project
     * @return Task
     */
    public function setProject(\Lan\CrmBundle\Entity\Project $project)
    {
        $this->project = $project;

        return $this;
    }

    /**
     * Get project
     *
     * @return \Lan\CrmBundle\Entity\Project
     */
    public function getProject()
    {
        return $this->project;
    }

    /**
     * Set category
     *
     * @param \Lan\CrmBundle\Entity\TaskCategory $category
     * @return Task
     */
    public function setCategory(\Lan\CrmBundle\Entity\TaskCategory $category)
    {
        $this->category = $category;

        return $this;
    }

    /**
     * Get category
     *
     * @return \Lan\CrmBundle\Entity\TaskCategory
     */
    public function getCategory()
    {
        return $this->category;
    }

    /**
     * Add products
     *
     * @param \Lan\CrmBundle\Entity\Product $products
     * @return Task
     */
    public function addProduct(\Lan\CrmBundle\Entity\Product $products)
    {
        $this->products[] = $products;

        return $this;
    }

    /**
     * Remove products
     *
     * @param \Lan\CrmBundle\Entity\Product $products
     */
    public function removeProduct(\Lan\CrmBundle\Entity\Product $products)
    {
        $this->products->removeElement($products);
    }

    /**
     * Get products
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getProducts()
    {
        return $this->products;
    }

    /**
     * Set user
     *
     * @param \Lan\SecurityBundle\Entity\User $user
     * @return Task
     */
    public function setUser(\Lan\SecurityBundle\Entity\User $user = null)
    {
        $this->user = $user;

        return $this;
    }

    /**
     * Get user
     *
     * @return \Lan\SecurityBundle\Entity\User
     */
    public function getUser()
    {
        return $this->user;
    }

    /**
     * Set deadline
     *
     * @param \DateTime $deadline
     * @return Task
     */
    public function setDeadline($deadline)
    {
        $this->deadline = $deadline;

        return $this;
    }

    /**
     * Get deadline
     *
     * @return \DateTime
     */
    public function getDeadline()
    {
        return $this->deadline;
    }

    /**
     * Set task
     *
     * @param \Lan\CrmBundle\Entity\Task $task
     * @return Task
     */
    public function setTask(\Lan\CrmBundle\Entity\Task $task = null)
    {
        $this->task = $task;

        return $this;
    }

    /**
     * Get task
     *
     * @return \Lan\CrmBundle\Entity\Task 
     */
    public function getTask()
    {
        return $this->task;
    }

    /**
     * Add tasks
     *
     * @param \Lan\CrmBundle\Entity\Task $tasks
     * @return Task
     */
    public function addTask(\Lan\CrmBundle\Entity\Task $tasks)
    {
        $this->tasks[] = $tasks;

        return $this;
    }

    /**
     * Remove tasks
     *
     * @param \Lan\CrmBundle\Entity\Task $tasks
     */
    public function removeTask(\Lan\CrmBundle\Entity\Task $tasks)
    {
        $this->tasks->removeElement($tasks);
    }

    /**
     * Get tasks
     *
     * @return \Doctrine\Common\Collections\Collection 
     */
    public function getTasks()
    {
        return $this->tasks;
    }
}

不要犹豫,问我任何进一步的信息。

最佳答案

default 是 mysql 保留字,你必须通过以下方式修复它:

/**
 * @ORM\Column(name="`default`", type="boolean", nullable=true)
 */
private $default;

关于php - 我的 Symfony2 应用程序出现语法错误或访问冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22168634/

相关文章:

mysql - 安排事件未执行

c# - Form.Close() 也正在关闭其他表单(对话框)

php - php 中的 levenshtein mysql 程序替代方案

php - 如何显示 MySQL 数据库条目的摘录?

mysql - 3306端口继续关闭,无法访问mysql

MYSQL:根据平均值对结果进行排序

php - 在提交之前等待管理员验证某些内容的最佳方法是什么?

PHP 相当于 MySQL 的 UNIX_TIMESTAMP()?

javascript - 表单提交成功后重定向

JavaScript - 在 'for' 循环中设置表单输入属性