0
Laravel 4에서 마이그레이션에 외래 키 제약 조건을 어떻게 추가 할 수 있습니까? (foreigntable
를 참조) mytable
의 이주에 Laravel 마이그레이션의 외래 키 제약
// add Column
$table
->string('foreigntable_id', 6);
// add FK
$table
->foreign('foreigntable_id')
->references('id')
->on('foreigntable');
오류 :
[Exception]
SQLSTATE[HY000]: General error: 1005 Can't create table 'mydb.#sql-1a24_2
1a' (errno: 150) (SQL: alter table `mytable` add constraint
mytable_foreigntable_id_foreign foreign key (`foreigntable_id`) references
`foreigntable` (`id`)) (Bindings: array (
))
나는 문제가 MySQL은 외부 키 제한 조건을 추가 할 때 foreigntable
이 존재하지 않는다고 가정 mytable
으로 변경하십시오 (foreigntable
을 생성하는 마이그레이션은 이후에만 으로 실행 됨)로 마이그레이션하십시오.이 완료되었습니다.)
이 문제를 해결하려면 어떻게해야합니까?