更新架构时出现FOSUserBundle错误的Symfony

时间:2016-05-13 12:17:10

标签: php symfony doctrine fosuserbundle

我遵循此主题http://symfony.com/doc/current/bundles/FOSUserBundle/index.html

我做了步骤1-6,但是当我必须更新数据库架构时。

$ php bin/console doctrine:schema:update --force

我收到了可怕的错误。

[Doctrine\DBAL\Exception\DriverException]
An exception occurred while executing 'CREATE TABLE fos_user (id INT AUTO_I
NCREMENT NOT NULL, username VARCHAR(255) NOT NULL, username_canonical VARCH
AR(255) NOT NULL, email VARCHAR(255) NOT NULL, email_canonical VARCHAR(255)
NOT NULL, enabled TINYINT(1) NOT NULL, salt VARCHAR(255) NOT NULL, passwor
d VARCHAR(255) NOT NULL, last_login DATETIME DEFAULT NULL, locked TINYINT(1
) NOT NULL, expired TINYINT(1) NOT NULL, expires_at DATETIME DEFAULT NULL,
confirmation_token VARCHAR(255) DEFAULT NULL, password_requested_at DATETIM
E DEFAULT NULL, roles LONGTEXT NOT NULL COMMENT '(DC2Type:array)', credenti
als_expired TINYINT(1) NOT NULL, credentials_expire_at DATETIME DEFAULT NUL
L, UNIQUE INDEX UNIQ_957A647992FC23A8 (username_canonical), UNIQUE INDEX UN
IQ_957A6479A0D96FBF (email_canonical), PRIMARY KEY(id)) DEFAULT CHARACTER S
ET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB':
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was  t
oo long; max key length is 767 bytes

有错误:

SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was t  
oo long; max key length is 767 bytes

我不知道如何修复它。有人可以帮忙吗?

顺便说一下。我正在使用Symfony 3!

1 个答案:

答案 0 :(得分:2)

替换

username_canonical VARCHAR(255) NOT NULL

username_canonical VARCHAR(191) NOT NULL

并使用email_canonical

执行相同的操作

如果您使用Doctrine ORM实体,则必须设置:

/**
 * @ORM\Column(type="string", unique=true, length=191)
 */
private $usernameCanonical;

查看长度= 191