Невозможно создать несколько первичных атрибутов
1 ответ
Эти ключи могут символизировать первичные ключи, внешние ключи, уникальные столбцы или индексы.
Вы не можете иметь более одного первичного ключа в таблице.
Вот что я пробовал:Диаграмма
php .\artisan make:model Employee -m
php .\artisan make:model Title -m
php .\artisan make:model Salary -m
class CreateTitlesTable extends Migration
{
public function up(): void
{
Schema::create('titles', function (Blueprint $table) {
$table->unsignedBigInteger('emp_no');
$table->string('title', 50)->index();
$table->date('from_date')->index();
$table->foreign('emp_no')->references('emp_no')->on('employees');
});
}
};
class CreateSalariesTable extends Migration
{
public function up(): void
{
Schema::create('salaries', function (Blueprint $table) {
$table->unsignedBigInteger('emp_no');
$table->integer('salary');
$table->date('from_date')->index();
$table->foreign('emp_no')->references('emp_no')->on('employees');
});
}
};
Редактировать
Предполагая, что несколько значков клавиш означают составную клавишу
class CreateEmployeesTable extends Migration
{
public function up(): void
{
Schema::create('employees', function (Blueprint $table) {
$table->bigIncrements('emp_no');
$table->string('first_name', 14);
$table->string('last_name', 16);
$table->date('birth_date');
$table->date('hire_date');
});
}
};
class CreateTitlesTable extends Migration
{
public function up(): void
{
Schema::create('titles', function (Blueprint $table) {
$table->unsignedBigInteger('emp_no');
$table->string('title', 50);
$table->date('from_date');
$table->foreign('emp_no')->references('emp_no')->on('employees');
$table->primary(['emp_no', 'title', 'from_date']);
});
}
};
class CreateSalariesTable extends Migration
{
public function up(): void
{
Schema::create('salaries', function (Blueprint $table) {
$table->unsignedBigInteger('emp_no');
$table->integer('salary');
$table->date('from_date');
$table->foreign('emp_no')->references('emp_no')->on('employees');
$table->primary(['emp_no', 'from_date']);
});
}
};