mardi 16 février 2016

Composite Key Constraint in Migration Class : Larvavel 5

My code is below.

Schema::create('tblsubcategory', function (Blueprint $table) {
    $table->increments('SubCategoryID');
    $table->integer('CategoryID');
    $table->string('SubCategory', 40);
    $table->timestamps();
});

In the above schema, CategoryID and SubCategory combination should be unique.

So far, I found about setting unique only single column. Can you suggest to do the same for multiple columns ?

My query is below.

ALTER TABLE tblsubcategory 
ADD CONSTRAINT UK_tblsubcategory_SubCategory_categoryID 
UNIQUE KEY (SubCategory, categoryID)



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire