当我安装 FOSUserBundle ( official documentation ) 时,我尝试使用以下命令生成我的表 fos_user
:
php app/console doctrine:schema:update --force
但控制台返回以下信息
Nothing to update - your database is already in sync with the current entity metadata
我使用 Symfony 2.1 和 FOSUserBundle 的最新版本。
app/AppKernel.php 包含
new FOS\UserBundle\FOSUserBundle(),
app/config/config.yml 包含
fos_user:
db_driver: orm # other valid values are 'mongodb', 'couchdb' and 'propel'
firewall_name: main
user_class: Krpano\UserBundle\Entity\User
src/Krpano/UserBundle/Entity/User.php包含
namespace Krpano\UserBundle\Entity;
use FOS\UserBundle\Entity\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="pouet")
*/
class User extends BaseUser
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
public function __construct()
{
parent::__construct();
// your own logic
}
}
当我尝试访问我的网站时出现此错误:
MappingException: The class 'Krpano\UserBundle\Entity\User' was not found in the chain configured namespaces FOS\UserBundle\Entity, Krpano\ServicesBundle\Entity
你能帮帮我吗?
最佳答案
Nothing to update - your database is already in sync with the current entity metadata
暗示您的实体未注册,因为 AppKernel.php 中缺少声明。
Doctrine 只搜索活跃的 bundle。
添加行后:
new Krpano\UserBundle\KrpanoUserBundle(),
像那样:
public function registerBundles()
{
$bundles = array(
...
new Krpano\UserBundle\KrpanoUserBundle(),
new FOS\UserBundle\FOSUserBundle(),
...
); ...
试试这个:
php app/console doctrine:schema:update --force
如果 Doctrine 返回:
Database schema updated successfully! "1" queries were executed
您的问题已解决。
我的回答只是对 Carlos Granados 回答的补充。
关于php - 无法生成表 "user",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12145283/