Здесь у меня три таблицы - клиенты | заказы | services .
Я пытаюсь добавить идентификатор таблицы клиентов и услуг в качестве внешнего ключа в таблицу заказов, но получаю сообщение об ошибке при переносе как ошибка 150. Я новичок в среде Laravel. Как я могу отладить это?
public function up()
{
Schema::create('customers', function (Blueprint $table) {
$table->increments('id');
$table->string('first_name');
$table->string('last_name');
$table->string('nic', 12)->unique();
$table->string('address');
$table->integer('phone_number', 10)->unique();
$table->integer('gender_id')->unsigned();
$table->date('dob');
$table->foreign('gender_id')->references('id')->on('genders');
$table->timestamps();
$table->softDeletes();
});
}
public function up()
{
Schema::create('services', function (Blueprint $table) {
$table->increments('id');
$table->string('service_name');
$table->timestamps();
});
}
public function up()
{
Schema::create('orders', function (Blueprint $table) {
$table->increments('id');
$table->integer('service_id')->unsigned();
$table->string('remark')->nullable();
$table->integer('customer_id')->unsigned();
$table->timestamps();
$table->foreign('customer_id')->references('id')->on('customers');
$table->foreign('service_id')->references('id')->on('services');
});
}
Сообщение об ошибке:
Illuminate\Database\QueryException : SQLSTATE[HY000]: General error: 1005 Can't create table `ocsas`.`orders` (errno: 150 "Foreign key constraint is incorrectly formed") (SQL: alter table `orders` add constraint `orders_customer_id_foreign` foreign key (`customer_id`) references `customers` (`id`))
at C:\xampp\htdocs\ocsas\vendor\laravel\framework\src\Illuminate\Database\Connection.php: 664
660: // If an exception occurs when attempting to run a query, we'll format the error
661: // message to include the bindings with SQL, which will make this exception a
662: // lot more helpful to the developer instead of just the database's errors.
663: catch (Exception $e) {
664: throw new QueryException(
665: $query, $this->prepareBindings($bindings), $e
666: );
667: }
668:
669: return $result;
Exception trace:
1 PDOException::("SQLSTATE[HY000]: General error: 1005 Can't create table `ocsas`.`orders` (errno: 150 "Foreign key constraint is incorrectly formed")")
C:\xampp\htdocs\ocsas\vendor\laravel\framework\src\Illuminate\Database\Connection.php : 458
2 PDOStatement::execute()
C:\xampp\htdocs\ocsas\vendor\laravel\framework\src\Illuminate\Database\Connection.php : 458
Please use the argument -v to see more details.