无法删除启用了FOSOAuthBundle的用户

时间:2017-11-13 09:42:16

标签: symfony fosuserbundle fosoauthserverbundle

我尝试删除symfony 3应用中的用户。我使用FOSOAuthBundleFOSUserBundle

我试过这段代码:

$em = $this->getDoctrine()->getManager();
$em->remove($user);
$em->flush();

但是我收到了这个错误:

An exception occurred while executing 'DELETE FROM user WHERE id = ?' with params [1]:\n\nSQLSTATE[23000]:
Integrity constraint violation: 1451 Cannot delete or update a parent row:
a foreign key constraint fails (`database`.`access_token`, CONSTRAINT `FK_B6A2DD68A76ED395` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`))

我有这个配置:

# FOSOAuthServerBundle configuration
fos_oauth_server:
    db_driver: orm
    client_class: OAuthBundle\Entity\Client
    access_token_class: OAuthBundle\Entity\AccessToken
    refresh_token_class: OAuthBundle\Entity\RefreshToken
    auth_code_class: OAuthBundle\Entity\AuthCode
    service:
        user_provider: fos_user.user_provider.username_email
        options:
            access_token_lifetime: 86400
            refresh_token_lifetime: 2.628e+6

如果我获得访问令牌,则用户字段始终为null,但在数据库中保存了正确的ID,并且可以使用此令牌登录。

1 个答案:

答案 0 :(得分:1)

你需要配置级联操作。删除用户时,您需要决定在access_token表上想要发生什么。您可以删除de token或将相关用户设置为null。

More info here