另一个“不一致的映射”,“拥有侧场不存在”的学说问题


Yet another "inconsistent mappings", "owning side field does not exist" Doctrine issue

我遇到了"映射 X 和 Y 彼此不一致"的教义错误,所以我首先在SE上浏览了一些类似的问题:

这个问题使多次使用相同的mappedby键的错误 - 不是我的情况。

这个问题犯了通过 ID 而不是对象引用将实体相互连接的错误。因为我不指定似乎不是我问题的类型(见下文)。

这个问题使用 yml 文件来指定映射 - 不是我的情况。

这个问题错误地命名了mappedByinversedBy键 - 据我所知,不是我的情况。

这个问题通过在注释中使用 FQCN 来解决,我做到了 - 见下文。

完整的错误消息:

$ php bin/console doctrine:schema:validate
[Mapping]  FAIL - The entity-class 'AppBundle'Entity'Comment' mapping is invalid:
* The mappings AppBundle'Entity'Comment#cmtauthor and AppBundle'Entity'User#comments are inconsistent with each other.
[Mapping]  FAIL - The entity-class 'AppBundle'Entity'User' mapping is invalid:
* The association AppBundle'Entity'User#comments refers to the owning side field AppBundle'Entity'Comment#cmtauthour which does not exist.
[Database] FAIL - The database schema is not in sync with the current mapping file.
$ 

这是我的课程的内容(为简单起见,我不包括由 Doctrine 自动生成的 getter/setter/constructor ):

namespace AppBundle'Entity;
use Doctrine'ORM'Mapping as ORM;
use Doctrine'Common'Collections'ArrayCollection;
use Symfony'Component'Validation'Constraints as Assert;
/**
* @ORM'Entity
* @ORM'Table(name="nruser")
*
**/
class User 
{
    /**
     * @ORM'Id
     * @ORM'GeneratedValue(strategy="AUTO")
     * @ORM'Column(type="integer")
     */
    private $id;
    /**
     * @ORM'OneToMany(
     *      targetEntity="AppBundle'Entity'Comment",
     *      mappedBy="cmtauthour",
     *      orphanRemoval=true
     * )
     * 
     */
    private $comments;
    /**
     * @ORM'OneToMany(
     *      targetEntity="AppBundle'Entity'Post",
     *      mappedBy="postauthor",
     *      orphanRemoval=true
     * )
     * 
     */
    private $posts;

}
/**
* @ORM'Entity
* @ORM'Table(name="post")
*
**/
class Post
{
    /**
     * @ORM'Id
     * @ORM'GeneratedValue(strategy="AUTO")
     * @ORM'Column(type="integer")
     */
    private $id;

    /**
     * @ORM'OneToMany(
     *      targetEntity="AppBundle'Entity'Comment",
     *      mappedBy="post",
     *      orphanRemoval=true
     * )
     * 
     */
    private $comments;
    /**
     * @ORM'ManyToOne(targetEntity="AppBundle'Entity'User", inversedBy="posts")
     * @ORM'JoinColumn(nullable=false)
     */
    private $postauthor;

}
/**
* @ORM'Entity
* @ORM'Table(name="comment")
*
**/
class Comment
{
    /**
     * @ORM'Id
     * @ORM'GeneratedValue(strategy="AUTO")
     * @ORM'Column(type="integer")
     */
    private $id;
    /**
     * @ORM'ManyToOne(targetEntity="AppBundle'Entity'Post", inversedBy="comments")
     * @ORM'JoinColumn(nullable=false)
     */
    private $post;
    /**
     * @ORM'ManyToOne(targetEntity="AppBundle'Entity'User", inversedBy="comments")
     * @ORM'JoinColumn(nullable=false)
     */
    private $cmtauthor;


}

任何帮助表示赞赏。

检查schema is not in sync转储架构更新查询的原因:

php app/console doctrine:schema:update --dump-sql