İlişkili tablo oluşturmaya çalışırken hata alıyorum.
1- users
2- packets
3- package_features
bu şekilde 3 adet tablom var.
Users Migration;
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->enum('type', ['provider', 'customer']);
$table->string('first_name');
$table->string('last_name');
$table->foreignId('package_id')->references('id')->on('packets');
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->softDeletes();
$table->timestamps();
});
Packets Migration;
Schema::create('packets', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->float('price');
});
Package Features Migration;
Schema::create('package_features', function (Blueprint $table) {
$table->id();
$table->foreignId('package_id')->references('id')->on('packets');
$table->string('feature');
});
php artisan migrate yaptığım zaman gelen hata;
PDOException:"SQLSTATE[HY000]: General error: 1005 Can't create table ptboxx.users (errno: 150 "Foreign key constraint is incorrectly formed")")
Benim asıl sormak istediğim "foreignId" ile oluşturduğumuz verileri sadece bununla oluşturacağız yoksa bunu ayrıca aşağı mı eklemem gerekiyor. Yani şöyle;
Önce;
$table->unsignedBigInteger('package_id');
Daha sonra;
$table->foreignId('package_id')->references('id')->on('packets');
yoksa sadece foreignId yeterli mi ?