问题
I have UserBundle who extends FOSUserBundle, and entity User who extends FOS's User class. On my localhost work fine, but on hosting i've got error:
Fatal error: Uncaught exception 'Doctrine\ORM\Mapping\MappingException' with message 'No identifier/primary key specified for Entity "WisJa\CoreBundle\Entity\User" sub class of "FOS\UserBundle\Model\User". Every Entity must have an identifier/primary key.' in...
My User entity all code:
<?php
namespace WisJa\CoreBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use FOS\UserBundle\Model\User as BaseUser;
/**
* @ORM\Table(name="fos_user")
* @ORM\Entity
*/
class User extends BaseUser
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var string
*
* @ORM\Column(name="facebook", type="string", nullable=true, length=255)
*/
protected $facebook;
public function __construct()
{
parent::__construct();
// your own logic
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set facebook
*
* @param string $facebook
* @return User
*/
public function setFacebook($facebook)
{
$this->facebook = $facebook;
return $this;
}
/**
* Get facebook
*
* @return string
*/
public function getFacebook()
{
return $this->facebook;
}
}
I have no idea why it works on localhost but don't works in web...
回答1:
You need to completely clear the cache
dir at your hosting. Sometimes it's better to do rm -rf var/cache/*
instead of using the Symfony console, but sometimes this could cause some permission issues. It depends on your server configuration.
来源:https://stackoverflow.com/questions/21267178/no-identifier-primary-key-specified-for-entity-extends-fos-user