я получаю сообщение об ошибке
SQLSTATE[HY000]: General error: 1005 Can't create tableposys.#sql-2b94_d2(errno: 150 "Foreign key constraint is incorrectly formed") (SQL: alter tableпокупка_заказовadd constraint
Purchase_orders_status_id_foreignforeign key (status_id) referencesстатусы(id))
При запуске моей миграции.
Вот мои миграции:
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateStaffTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('staff', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name')->unique();
$table->string('position')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('staff');
}
}
А также
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreatePurchaseOrdersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('purchase_orders', function (Blueprint $table) {
$table->bigIncrements('id');
$table->float('total_price_ex_vat', 12, 2);
$table->float('total_price_inc_vat', 12, 2);
$table->string('deliver_to');
$table->unsignedBigInteger('staff_id'); // Foreign key
$table->foreign('staff_id')->references('id')->on('staff');
$table->unsignedBigInteger('supplier_id'); // Foreign key
$table->foreign('supplier_id')->references('id')->on('suppliers');
$table->unsignedBigInteger('status_id'); // Foreign key
$table->foreign('status_id')->references('id')->on('statuses');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('purchase_orders');
}
}

Ваш большой int несовместим с вашим unsigned big int:
$table->unsignedBigInteger('staff_id'); // on purchase orders
против:
$table->bigIncrements('id'); // on staff
просто используйте обычный большой int для staff_id или сделайте id вашего персонала беззнаковым
Спасибо за ваш ответ. Я изменил unsignedBigInteger на BigInteger, но все равно получаю ту же ошибку.
Можете ли вы попробовать удалить новые таблицы из своей базы данных и убедиться, что в таблице migrations перечислены только оставшиеся таблицы?
Вы выполнили замену unsignedBigInteger на BigInteger для всех unsignedBigInteger или только для staff_id?
Да, я проверил все миграции и изменил все внешние ключи на BigInteger
@Rob_Beirmann Я также добавил ->unsigned() к внешним ключам, и теперь это работает. $table->BigInteger('staff_id')->unsigned(); // Foreign key
Чтобы избежать ошибки 150, выберите один:
CREATE TABLEsDISABLE FKs, делайте творения, активируйте их.ADD FK, пока не будут выполнены все CREATEs.
Пожалуйста, поделитесь кодом миграции (тип данных id) для модели статуса