我有这个模式构建器(我省略了类扩展和模式下部分)
public function up()
{
Schema::create('cat', function(Blueprint $table)
{
$table->bigIncrements('id');
$table->timestamps();
$table->string('path_img');
$table->softDeletes();
});
}
这样:
public function up()
{
Schema::create('campo', function(Blueprint $table)
{
$table->bigIncrements('id');
$table->timestamps();
$table->string('nome');
});
}
和此:
public function up()
{
Schema::create('campo_cat', function(Blueprint $table)
{
$table->timestamps();
$table->bigInteger('id_campo')->unsigned();
$table->bigInteger('id_cat')->unsigned();
$table->primary(array('id_campo','id_cat'));
$table->foreign(array('id_campo','id_cat'))->references(array('id','id'))->on(array('campo','cat'));
});
}
我要做的是声明表'campo_cat'有2个条目是BOTH主键,也是外键,引用cat id和campo id。
1)如果我在迁移时使用unsigned,我会得到一个数组到字符串转换错误异常 2)是否需要签名?或者我可以定义:
$table->unsigned('..');
同时1)和2)campo_cat不会创建
问题似乎与:
有关$table->foreign(array('id_campo','id_cat'))
->references(array('id','id'))
->on(array('campo','cat'));
编辑:
我设法通过这样做来实现:
public function up()
{
Schema::create('campo_cat', function(Blueprint $table)
{
$table->timestamps();
$table->bigInteger('id_campo')->unsigned();
$table->bigInteger('id_cat')->unsigned();
$table->primary(array('id_campo','id_cat'));
$table->foreign('id_campo')->references('id')->on('campo');
$table->foreign('id_cat')->references('id')->on('cat');
});
}
添加
->unsigned(); //to the primary key in the other 2 scheme
仍然想知道为什么如果我使用数组它会引发错误。