Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Need to define 02 primary keys in here

I want to define 02 primary keys in this migration , also i need to define it in model class. i m using laravel 9 version . When i define this . it gives following error.

Schema::create('salaries', function (Blueprint $table) {
            $table->increments('id')->primary();
            $table->unsignedInteger('emp_no')->primary();
            $table->foreign('emp_no')->references('id')->on('employees')->cascadeOnDelete()->cascadeOnUpdate();
            $table->integer('salary');
            $table->date('from_date')->primary();
            $table->date('to_date');
            $table->timestamps();
        });

Output

 SQLSTATE[42000]: Syntax error or access violation: 1068 Multiple primary key defined (SQL
: alter table `titles` add primary key `titles_id_primary`(`id`))

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Try this way, here is my e.g:

Schema::create("kitchen", function($table) {
    $table->increments('id');
    $table->integer('restaurant_id');
    $table->string('name');
    $table->unique(['restaurant_id', 'name']);
});
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading