Не удалось вставить внешний ключ - PullRequest
0 голосов
/ 13 мая 2019

У меня есть две таблицы: ученики и родитель. Я создал внешний ключ для таблицы учеников, который ссылается на идентификатор родителя, но когда я вставляю данные, столбец внешнего идентификатора становится пустым из базы данных

Schema::create('students', function (Blueprint $table) {
    $table->bigIncrements('id');
    $table->bigInteger('pregistration_id')->unsigned();
    $table->integer('admission_no')->unique();
    $table->string('fname');
    $table->string('mname');
    $table->string('lname');
    $table->date('dob');
    $table->string('primary_school');
    $table->string('form_enrolled');
    $table->string('transfered_from');
    $table->string('transfered_to');
    $table->foreign('pregistration_id')->references('id')
        ->on('pregistrations');
    $table->timestamps();
Schema::create('pregistrations', function (Blueprint $table) {
    $table->engine = 'InnoDB';
    $table->bigIncrements('id')->unsigned();
    $table->string('fname');
    $table->string('mname');
    $table->string('lname');
    $table->string('residence');
    $table->integer('phone');
    $table->string('occupation');
    $table->timestamps();

Мои контроллеры

return Student::create([
    'pregistration_id'=>$request['pregistration_id'],
    'admission_no'=>$request['admission_no'],
    'fname'=>$request['fname'],
    'mname'=>$request['mname'],
    'lname'=>$request['lname'],
    'dob'=>$request['dob'],
    'primary_school'=>$request['primary_school'],
    'form_enrolled'=>$request['form_enrolled'],
    'transfered_from'=>$request['transfered_from'],
    'transfered_to'=>$request['transfered_to'],

Компонент

<tr v-for="student in students" :key="student.id">
    <div v-for="pregistration in pregistrations" 
        :key="pregistration.id"></div>
    <td>{{student.id}}</td>
    <td>{{student.admission_no}}</td>
    <td>{{student.fname|upText}}</td>
    <td>{{student.mname|upText}}</td>
    <td>{{student.lname|upText}}</td>
    <td>{{student.dob}}</td>
    <td>{{student.primary_school|upText}}</td>
    <td>{{student.form_enrolled|upText}}</td>
    <td>{{student.transfered_from|upText}}</td>
    <td>{{student.transfered_to|upText}}</td>

Пожалуйста, кто-нибудь, кто может помочь мне в этом

Ниже приведен код моего компонента

<form @submit.prevent="editmode ? updateStudent() : insertStudent()">
                         <div class="modal-body">
                            <!-- Students registration form start from here-->
                                <div class="form-group">
                                <input v-model="form.admission_no" type="text" name="admission_no" placeholder="Admission Number"
                                    class="form-control" :class="{ 'is-invalid': form.errors.has('admission_no') }">
                                <has-error :form="form" field="admission_no"></has-error>
                                </div>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...