我一直在laravel问题/论坛中搜索如何使用现有表将更改从increments()
迁移到bigIncrements()
。
错误:SQLSTATE[HY000]: General error: 1833 Cannot change column 'id': used in a foreign key constraint 'account_users_acc_id_foreign' of table 'mydatabasename.account_users' (SQL: ALTER TABLE accounts CHANGE id id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL)
由于外部表,我知道它的存在,然后我尝试使用Schema::disableForeignKeyConstraints()
错误:SQLSTATE[HY000]: General error: 1025 Error on rename of './mydatabasename/#sql-ea_201' to './mydatabasename/accounts' (errno: 150 - Foreign key constraint is incorrectly formed) (SQL: ALTER TABLE accounts CHANGE id id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL)
在我的up()
函数中:
我还试图切换循环的顺序
错误:SQLSTATE[HY000]: General error: 1832 Cannot change column 'acc_id': used in a foreign key constraint 'account_users_acc_id_foreign' (SQL: ALTER TABLE account_users CHANGE acc_id acc_id BIGINT UNSIGNED DEFAULT NULL, CHANGE app_user_id app_user_id BIGINT UNSIGNED NOT NULL, CHANGE approved_by approved_by BIGINT UNSIGNED DEFAULT NULL, CHANGE rejected_by rejected_by BIGINT UNSIGNED DEFAULT NULL)
有什么办法解决这个问题?
参考文献:
DBAL学说:https://www.doctrine-project.org/projects/doctrine-dbal/en/2.9/reference/schema-manager.html
答案 0 :(得分:1)
可以吗?
[$table_name => $array_of_foreign_keys]
的数组中id
列更改为使用bigIncrements
unsigned big integer
答案 1 :(得分:0)
我尝试实现建议的@brice。现在就可以了。
下面是迁移代码。我不知道这是否是最佳做法
这是我的要旨:https://gist.github.com/afiqiqmal/6518a2048246cd76c03bdee04ff87a82