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.