dongyirong3564 2016-03-10 10:46
浏览 85
已采纳

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

I encountered a "mappings X and Y are inconsistent with each other" Doctrine error, so I starting by browsing a little bit similar questions here on SE :

This question makes the mistake of using the same mappedby key several times - not my case.

This question makes the mistake of connecting entities to one another by ID's rather than object references. As I do not specify the types (see below) that does not seem to be my problem.

This question uses yml files to specify mappings - not my case.

This question incorrectly names the mappedBy and inversedBy keys - not my case as far as I can see.

This question is solved by using FQCN inside the annotations, which I did - see below.

The complete error message :

$ 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.
$ 

And here are the contents of my classes (for simplicity I don't include the getters/setters/constructors automatically generated by Doctrine ) :

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;




}

Any help appreciated.

  • 写回答

1条回答 默认 最新

  • 普通网友 2016-03-10 12:22
    关注

    To check why schema is not in sync dump schema update queries:

    php app/console doctrine:schema:update --dump-sql
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示