如何解决无法创建表`nuevosem_laravel`.assignatures(错误号:150“外键约束格式不正确”)

时间:2019-08-05 23:37:45

标签: laravel-5 laravel-migrations

我正在尝试迁移一些文件,但是当我尝试迁移“主题”迁移文件时,工匠输出:

Illuminate \ Database \ QueryException:SQLSTATE [HY000]:常规错误:1005无法创建表nuevosem_laravelsubjects(错误号:150“外键约束格式不正确”)(SQL:更改表subjects添加约束subjects_teacher_foreign外键(teacher)引用teachersname))

我正在Xampp 3.2.4上运行Laravel

“教师”模式:

  Schema::create('teachers', function (Blueprint $table) {
      $table->increments('id')->unsigned();
      $table->string('name');
      $table->string('code')->unique();
      $table->timestamps();
  });

“主题”模式:

Schema::create('subjects', function (Blueprint $table) {

      $table->string('period');
      $table->string('teacher');
      $table->foreign('teacher')->references('name')->on('teachers');
      $table->integer('nrc')->unsingned();
      $table->string('key');
      $table->string('section');
      $table->enum('type', ['TEO', 'LAB']);
      $table->string('schedule');
      $table->string('days');
      $table->string('classroom');
      $table->string('subject');
      $table->timestamps();
  });

0 个答案:

没有答案