将主键数据类型从整数更改为Bigint时,Symfony 2架构更新失败

时间:2016-09-27 09:29:11

标签: php mysql symfony doctrine-orm

我有一个用户表,列id为主键。我在其他几个表中引用了这一列。现在我想将users table id列的数据类型更改为Bigint。所以,我将'integer'更改为'bigint'并成功生成实体。但是,如果我尝试更新架构,它将失败。请在此建议。

主表(用户)yml:

table: users
id:
    id:
        type: bigint
        generator: { strategy: AUTO }

示例引用表(user_profiles)yml:

oneToOne:
    user_id:
      targetEntity: Users
      inversedBy: userprofile
      joinColumn:
        name: user_id
        referencedColumnName: id

错误

  

php app / console doctrine:schema:update --force

     

[学说\ DBAL \异常\ DriverException]    执行'ALTER TABLE user_claim A时发生异常    DD CONSTRAINT FK_CDFFA2C4A76ED395 FOREIGN KEY(user_id)REFERENCES users(id)':    SQLSTATE [HY000]:常规错误:1215无法添加外键约束

我也尝试在MySql命令提示符中SET FOREIGN_KEY_CHECKS=0;。但没用。

1 个答案:

答案 0 :(得分:1)

您需要将其他表中的外键列更新为与ID(bigint)相同的类型。

看看:Setting up foreign key with different datatype