Внешний ключ не создается - PullRequest
1 голос
/ 12 ноября 2019

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

Сначала я создал две таблицы: таблицу пользователей и таблицу курсов.

if(! Schema::hasTable('users')) {
            Schema::create('users', function (Blueprint $table) {
                $table->increments('id');
                $table->string('name');
                $table->string('email');
                $table->string('password');
                $table->string('remember_token')->nullable();

                $table->timestamps();

            });
        }
if(! Schema::hasTable('courses')) {
            Schema::create('courses', function (Blueprint $table) {
                $table->increments('id');
                $table->string('title');
                $table->string('slug')->nullable();
                $table->text('description')->nullable();
                $table->decimal('price', 15, 2)->nullable();
                $table->string('course_image')->nullable();
                $table->date('start_date')->nullable();
                $table->tinyInteger('published')->nullable()->default(0);

                $table->timestamps();
                $table->softDeletes();

                $table->index(['deleted_at']);
            });
        }

Затем я создал еще одну таблицу под названием «учителя» с внешними ключами

if(! Schema::hasTable('teacher')) {
            Schema::create('teacher', function (Blueprint $table) {
                $table->increments('id');
                $table->integer('user_id')->unsigned();
                $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
                $table->integer('course_id')->unsigned();
                $table->foreign('course_id')->references('id')->on('courses')->onDelete('cascade');
                $table->string('teachers_image')->nullable();
                $table->text('education')->nullable();
                $table->text('contact')->nullable();

                $table->timestamps();
                $table->softDeletes();

            });
        }

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

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...