首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >字段“usernameCanonical”不是由Doctrine映射的,因此无法验证其唯一性

字段“usernameCanonical”不是由Doctrine映射的,因此无法验证其唯一性
EN

Stack Overflow用户
提问于 2016-09-30 10:14:25
回答 1查看 1.3K关注 0票数 1

我在我的Symfony 2.7项目中使用FOSUserBundle。在composer.json文件中,需求被定义为"friendsofsymfony/user-bundle" : "~2.0@dev"。目前已安装/commit 45d6f40 (11/03/2015)。

使用composer update后,安装了最新版本的7abb0ff。在此之后,在尝试创建新用户时,我会得到以下异常:

字段“usernameCanonical”不是由Doctrine映射的,因此无法验证其唯一性

为该问题寻找解决方案会引发处理相同异常的旧问题(这里这里)。然而,我无法用这些问题中讨论的解决方案来解决问题。

第1565期建议使用FOS\UserBundle\Entity\User as BaseUser;而不是FOS\UserBundle\Model\User as BaseUser;。但是这个解决方案似乎不适用于2.x版本。2.x文档说您应该从FOS\UserBundle\Model\User扩展,这是有意义的,因为已经没有FOS\UserBundle\Entity\...类了。

我的用户类如下所示:

代码语言:javascript
复制
namespace AppBundle\Entity;

use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;

/**
 * This class represents the User entity and extends the FOSBundle base user
 * Entity class to be able to use FOSUserBundle to manage the application users.
 *
 * @ORM\Entity(repositoryClass="AppBundle\Entity\UserRepository")
 * @ORM\Table(name="app_user") * 
 * @ORM\HasLifecycleCallbacks()
 */
class User extends BaseUser {
    ...
}

第1638期中,解决方案是在原则配置中使用auto_mapping。我已经做过了。

所以现有的解决方案都不适合我。此外,除了这个问题之外,现有的所有问题都很老了。

当然,我可以简单地降级到版本/提交45d6f40。然而,我更愿意解决这个问题,而不是忽视它:-)

还有其他办法解决这个问题吗?

PS:这是我的composer show -i输出:

代码语言:javascript
复制
doctrine/annotations                 v1.2.7             Docblock Annotations Parser
doctrine/cache                       v1.6.0             Caching library offering an object-oriented API for many cache backends
doctrine/collections                 v1.3.0             Collections Abstraction library
doctrine/common                      v2.6.1             Common Library for Doctrine projects
doctrine/dbal                        v2.4.5             Database Abstraction Layer
doctrine/doctrine-bundle             v1.2.0             Symfony DoctrineBundle
doctrine/inflector                   v1.0.1             Common String Manipulations with regard to casing and singular/plural rules.
doctrine/instantiator                1.0.5              A small, lightweight utility to instantiate objects in PHP without invoking their constructors
doctrine/lexer                       v1.0.1             Base library for a lexer that can be used in Top-Down, Recursive Descent Parsers.
doctrine/orm                         v2.4.8             Object-Relational-Mapper for PHP
friendsofsymfony/http-cache          1.4.0              Tools to manage cache invalidation
friendsofsymfony/http-cache-bundle   1.3.4              Set path based HTTP cache headers and send invalidation requests to your HTTP cache
friendsofsymfony/rest-bundle         1.4.2              This Bundle provides various tools to rapidly develop RESTful API's with Symfony2
friendsofsymfony/user-bundle         dev-master 7abb0ff Symfony FOSUserBundle
gremo/buzz-bundle                    v1.1.0             Symfony Bundle for using the lightweight Buzz HTTP client.
guzzle/guzzle                        v3.9.3             PHP HTTP client. This library is deprecated in favor of https://packagist.org/packages/guzzlehttp/guzzle
jdorn/sql-formatter                  v1.2.17            a PHP SQL highlighting library
jms/metadata                         1.5.1              Class/method/property metadata management in PHP
jms/parser-lib                       1.0.0              A library for easily creating recursive-descent parsers.
jms/serializer                       1.3.1              Library for (de-)serializing data of any complexity; supports XML, JSON, and YAML.
jms/serializer-bundle                1.1.0              Allows you to easily serialize, and deserialize data of any complexity
kriswallsmith/assetic                v1.3.2             Asset Management for PHP
kriswallsmith/buzz                   v0.15              Lightweight HTTP client
leafo/scssphp                        v0.6.6             scssphp is a compiler for SCSS written in PHP.
moontoast/math                       1.1.0              A mathematics library, providing functionality for large numbers
paragonie/random_compat              v2.0.2             PHP 5.x polyfill for random_bytes() and random_int() from PHP 7
phpcollection/phpcollection          0.5.0              General-Purpose Collection Library for PHP
phpoption/phpoption                  1.5.0              Option Type for PHP
psr/log                              1.0.0              Common interface for logging libraries
sensio/distribution-bundle           v2.3.22            The base bundle for the Symfony Distributions
sensio/framework-extra-bundle        v2.3.4             This bundle provides a way to configure your controllers with annotations
sensio/generator-bundle              v2.3.5             This bundle generates code for you
swiftmailer/swiftmailer              v5.4.3             Swiftmailer, free feature-rich PHP mailer
symfony/assetic-bundle               v2.7.1             Integrates Assetic into Symfony2
symfony/monolog-bundle               v2.8.2             Symfony MonologBundle
symfony/swiftmailer-bundle           v2.3.11            Symfony SwiftmailerBundle
symfony/symfony                      v2.7.7             The Symfony PHP framework
tfox/mpdf-port-bundle                1.3.1              A wrapper for mPDF class which allows to use mPDF in Symfony2 projects
twig/extensions                      v1.0.1             Common additional features for Twig that do not directly belong in core
twig/twig                            v1.25.0            Twig, the flexible, fast, and secure template language for PHP
willdurand/jsonp-callback-validator  v1.1.0             JSONP callback validator.
willdurand/negotiation               1.5.0              Content Negotiation tools for PHP provided as a standalone library.
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-06-05 22:00:54

也许这会在你得到错误的时候解决某人的问题。

字段“usernameCanonical”不是由Doctrine映射的,因此无法验证其唯一性

原因之一是使用FOS\UserBundle\Model\User作为BaseUser并运行理论模式:update,如果这样做,您将在数据库中创建一个没有用户名、usernameCanonical、密码等列的表。

当您想要访问任何功能时,您将得到该消息。

如何修复:

  1. 在数据库中删除表fos_user
  2. FOS\UserBundle\Model\User as BaseUser更改为FOS\UserBundle\Entity\User as BaseUser
  3. 运行php app/console doctrine:schema:update --force
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39789102

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档