Laravel MariaDB语法错误,因为字符串外键

时间:2016-09-27 11:07:59

标签: php html laravel mariadb

我已经使用这个论坛很长时间了,但这是我的第一个问题。我在一个Laravel项目中和一位朋友一起工作,今天我发现了一个奇怪的情况。 我使用Laravel Migration System(php artisan migrate:...)创建数据库,但是现在我无法将字符串设置为外键。 我的代码看起来像:

车辆表

    public function up()
{
  Schema::create('vehiculos', function (Blueprint $table) {
    $table->increments('id');
    $table->string('matricula')->unique(); <----------
    $table->string('marca');
    $table->string('modelo');
    $table->string('color');
    $table->integer('cliente_id')->length(10)->unsigned();
    $table->foreign('cliente_id')->references('id')->on('clientes')->onDelete('restrict');
    $table->timestamps();
  });
}

赔偿表

    public function up()
{
  Schema::create('reparaciones', function (Blueprint $table) {
    $table->increments('id');
    $table->string('fechaE');
    $table->string('fechaS');
    $table->string('horas');
    $table->string('km');
    $table->string('observaciones');
    $table->string('matricula')->nullable(); <-----------
    $table->foreign('matricula')->references('matricula')->on('vehiculos');
    $table->timestamps();
  });
}

使用 - &gt; nulleable()停止崩溃,但我认为这根本不正确。有人可以尝试以正确的方式解释我吗? 很高兴参加那个论坛。

0 个答案:

没有答案