执行以下操作:
下面的 Schema 将进入下的 schema-migrations 文件public function up()
//Create ** category table **
Schema:Create ('category',function ($table)){
//Relation: category table id used as FK -> to -> product table category_id
$table->increments('category_id');
//category name
$table->string('category_name',40)->unique();
//time staps: created,Updated
$table->timestamps();
}
比,内部产品架构:
//Create ** product table **
Schema::create('products', function ($table){
//product id
$table->increments('product_id');
//product name
$table->string('p_name')->unique();
//product description
$table->text('p_description');
//created_at and updated_at column
$table->timestamps();
//Foregine Key
$table->integer('category_id_fk')->unsigned();
//Foreign Key link to category table
$table->foreign('category_id_fk')->references('category_id')->on('category');
}