我在Laravel有问题,我不知道问题出在哪里。有人可以帮助我。并预先感谢您。 我有两个表(客户和赔偿) 我想用字符串字段('cin_client')创建外键,当我创建表修复时,它不再起作用 / * *************表客户**************>
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateClientsTable extends Migration
{
public function up()
{
Schema::create('clients', function (Blueprint $table) {
$table->Increments('id_client');
$table->string('nom_client');
$table->string('prenom_client');
$table->string('adresse_client');
$table->string('tel_client');
$table->string('cin_client',30);
$table->timestamps();
});
}
public function down()
{
Schema::dropIfExists('clients');
}
}
/ *************表格赔偿************* /
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateReparationsTable extends Migration
{
public function up()
{
Schema::create('reparations', function (Blueprint $table) {
$table->Increments('id_reparation');
$table->string('type_reparation')->nullable();
$table->string('date_reparation')->nullable();
$table->integer('prix_reparation')->nullable();
$table->string('genre_marque_type')->nullable();
$table->boolean('etat_reparation')->nullable();
/*$table->foreign('client_cin')->references('cin_client')->on('clients');*/
$table->timestamps();
$table->string('client_cin',30);
});
Schema::table('reparations', function (Blueprint $table){
$table->foreign('client_cin')->references('cin_client')->on('clients');
});
}
public function down()
{
Schema::dropIfExists('reparations');
}
}
答案 0 :(得分:0)
因此,该数据库错误几乎总是意味着您定义为在第一个表中保存外键引用的列和您在第二个表中定义的列都不匹配格式或长度。查看迁移情况(不确定使用的是哪种DBS),我认为您需要从reparations.client_cin的列定义中删除->unsigned()
。