首页 > 解决方案 > 当我有密钥对类型的数据时如何规范化表

问题描述

我正在制作一个平台,培训师可以在其中将课程添加到他的个人资料中。但在他添加课程之前,需要完成申请接受。

所以,我之前将我的数据库分为三个部分:

users | trainer | course

经过一些研究,我发现我必须进行数据库规范化,但我在设置它时遇到了问题。

现在我有trainer桌子trainer_experiencetrainer_achievements桌子。在培训师经验表中,我必须保存他们所穿职位和公司名称的数据。

我的教练表是这样的:

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateTrainersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('trainers', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedBigInteger('user_id');
            $table->date('date_of_birth');
            $table->integer('mobile_number');
            $table->longText('address');
            $table->string('id_proof');
            $table->string('id_registration_number');
            $table->string('high_school_name');
            $table->string('graduation_college_name');
            $table->string('graduation_course_name');
            $table->string('post_graduation_college_name');
            $table->string('post_graduation_course_name');
            $table->string('phd_field_of_study');
            $table->string('total_duration_of_training');
            $table->integer('no_of_people_trained');
            $table->boolean('paid_training');
            $table->string('training_category');
            $table->string('course_material_ready');
            $table->string('youtube_link')->nullable();
            $table->string('twitter_link')->nullable();
            $table->string('instagram_link')->nullable();
            $table->string('facebook_link')->nullable();
            $table->string('linkedin_link')->nullable();
            $table->string('blog_link')->nullable();
            $table->string('website_link')->nullable();
            $table->string('meetup_group_link')->nullable();    
            $table->timestamps();

            $table->index('user_id');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('trainers');
    }
}

我如何存储数据,以便我至少可以按照他们输入的顺序检索它?我需要制作两张不同的桌子吗?我有什么最好的选择?

标签: laravel-5npm

解决方案


  1. trainer_experience您必须在数据中找出trainer_achievements是否可重用?
  2. trainer_experience并且trainer_achievements相互依赖?
  3. 使用多态关系以获得最佳用途。

推荐阅读