删除带有外键 Laravel 错误的列:一般错误:1025 重命名错误
问题描述
I've created a table using migration like this:
I need to change this table and drop the foreign key reference & column pick_detail_id
and add a new varchar column called sku
after pick_id
column.
So, I've created another migration, which looks like this:
When I run this migration, I get the following error:
[IlluminateDatabaseQueryException]
SQLSTATE[HY000]: General error: 1025 Error on rename of './dev_iwms_reboot/despatch_discrepancies' to './dev_iwms_reboot/#sql2-67c-17c464' (errno: 152) (SQL: alter tabledespatch_discrepancies
drop foreign key pick_detail_id)[PDOException]
SQLSTATE[HY000]: General error: 1025 Error on rename of './dev_iwms_reboot/despatch_discrepancies' to './dev_iwms_reboot/#sql2-67c-17c464' (errno: 152)
When I try to reverse this migration by running php artisan migrate:rollback
command, I get a Rolled back
message, but it's not actually doing anything in the database.
Any idea what might be wrong? How do you drop a column that has a foreign key reference?
It turns out; when you create a foreign key like this:
Laravel uniquely names the foreign key reference like this:
Therefore, when you want to drop a column with foreign key reference, you have to do it like this:
Update:
Laravel 4.2+ introduces a new naming convention:
这篇关于删除带有外键 Laravel 错误的列:一般错误:1025 重命名错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!