【问题标题】:Symfony 3 Doctrine MySQL - generate entities with @ORM annotationsSymfony 3 Doctrine MySQL - 使用 @ORM 注释生成实体
【发布时间】:2016-07-19 21:05:19
【问题描述】:

运行 3 个命令后根据 Symfony 3 文档:

php bin/console doctrine:mapping:import --force AcmeBlogBundle xml
php bin/console doctrine:mapping:convert annotation ./src
php bin/console doctrine:generate:entities AcmeBlogBundle

我应该得到类似的结果:

// src/Acme/BlogBundle/Entity/BlogComment.php
namespace Acme\BlogBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * Acme\BlogBundle\Entity\BlogComment
 *
 * @ORM\Table(name="blog_comment")
 * @ORM\Entity
 */
class BlogComment
{
    /**
     * @var integer $id
     *
     * @ORM\Column(name="id", type="bigint")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $id;

    /**
     * @var string $author
     *
     * @ORM\Column(name="author", type="string", length=100, nullable=false)
     */
    private $author;
    .....

不幸的是,我没有得到大致映射的类,getter 和 setter 看起来像这样:

<?php
namespace Clashers\PanelBundle\Entity;

/**
 * Users
 */
class Users
{
    /**
     * @var string
     */
    private $username;

    /**
     * Set username
     *
     * @param string $username
     *
     * @return Users
     */
    public function setUsername($username)
    {
        $this->username = $username;

        return $this;
    }

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

你们中是否有人遇到过这样的问题并且已经解决了,而无需手动将每个属性分配给数据库类型、列? 是否有任何我错过了正确生成这些实体的 Doctrine 设置?

【问题讨论】:

  • 您是否有可能将这些文件乱序运行?考虑删除生成的 xml 映射文件以及实体文件,然后重试。
  • 你检查过你的数据库用户表吗?它应该反映您的表结构。如果您的表设置不正确,这可能就是原因。
  • 而且你肯定需要删除生成的 xml 映射文件。
  • @Cerad 我已经运行了 2 次命令,效果相同。在第二次运行之前删除了 xml 和实体。
  • @Sarcoma 我正在使用 MySQL DB,“正确设置”是什么意思?

标签: orm console doctrine symfony entities


【解决方案1】:

好的,问题解决了。我刚刚再次重新运行了这些命令,不知何故我错过了一个由已经创建用户实体引起的错误。这可能会阻止 Doctrine 创建其他实体并运行最后一个命令

php bin/console doctrine:generate:entities AcmeBlogBundle

没有完全处理

php bin/console doctrine:mapping:convert annotation ./src

最终会像我一样丢失注释。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-18
    • 2017-03-16
    • 2015-03-22
    • 2017-12-01
    相关资源
    最近更新 更多