У меня проблемы с миграциями в Ларавеле.Я продолжаю получать сообщение об ошибке, что ограничение внешнего ключа плохо сформировано.Кажется, я тоже не вижу, что я делаю неправильно.Названия миграций, чтобы они выполнялись в правильном порядке, на месте.Я также пытался запустить одну и одну миграцию, и она всегда останавливается на второй миграции (муниципалитеты).
Что я здесь не так делаю?
1-й стол: графства
public function up()
{
Schema::create('counties', function (Blueprint $table) {
$table->bigIncrements('id')->unsigned();
$table->string('name');
$table->timestamps();
});
DB::statement('ALTER TABLE counties CHANGE id id INT(2) UNSIGNED ZEROFILL NOT NULL');
}
2-й стол: муниципалитеты
public function up()
{
Schema::create('municipalities', function (Blueprint $table) {
$table->bigIncrements('id')->unsigned();
$table->bigInteger('county_id')->unsigned();
$table->foreign('county_id')->references('id')->on('counties')->onDelete('cascade');
$table->string('name');
$table->timestamps();
});
DB::statement('ALTER TABLE municipalities CHANGE county_id county_id INT(2) UNSIGNED ZEROFILL NOT NULL');
DB::statement('ALTER TABLE municipalities CHANGE id id INT(4) UNSIGNED ZEROFILL NOT NULL');
}
3-й стол: почтовые отправления
public function up()
{
Schema::create('postals', function (Blueprint $table) {
$table->bigIncrements('id')->unsigned();
$table->bigInteger('municipality_id')->unsigned();
$table->foreign('municipality_id')->references('id')->on('municipalities')->onDelete('cascade');
$table->string('name');
$table->timestamps();
});
DB::statement('ALTER TABLE postals CHANGE municipality_id municipality_id INT(4) UNSIGNED ZEROFILL NOT NULL');
DB::statement('ALTER TABLE postals CHANGE id id INT(6) UNSIGNED ZEROFILL NOT NULL');
}
4-я таблица: zips
public function up()
{
Schema::create('zips', function (Blueprint $table) {
$table->bigIncrements('id')->unsigned();
$table->bigInteger('postal_id')->unsigned();
$table->foreign('postal_id')->references('id')->on('postals')->onDelete('cascade');
$table->decimal('lat', 12, 7);
$table->decimal('lon', 12, 7);
$table->timestamps();
});
DB::statement('ALTER TABLE zips CHANGE id id INT(4) UNSIGNED ZEROFILL NOT NULL');
DB::statement('ALTER TABLE zips CHANGE postal_id postal_id INT(6) UNSIGNED ZEROFILL NOT NULL');
}
И сообщение об ошибке, которое я получаю: ![enter image description here](https://i.stack.imgur.com/E2FDf.png)