I need your help, I am making a list of tables in laravel with migration, which tables are 'Products', 'inputs' and 'ProductProduct', the relationship or database would be from 1 to many (1 product has N inputs) but this error appears:
1215 Can not add foreign key constraint
Sent them the migration code
Product Migration
public function up()
{
Schema::create('productos', function (Blueprint $table) {
$table->increments('id');
$table->String('nombreP')->unique();
$table->String('categoriaP');
$table->integer('valorP');
$table->String('UmedidaP');
$table->timestamps();
});
}
migration inputs
public function up()
{
Schema::create('insumos', function (Blueprint $table) {
$table->increments('id');
$table->String('nombreI')->unique();
$table->String('categoriaI');
$table->integer('valorI');
$table->String('UmedidaI');
$table->timestamps();
});
}
Detalleproducto migracion
public function up()
{
Schema::create('detalleproductos', function (Blueprint $table) {
$table->increments('id');
$table->Integer('id_producto');
$table->Integer('id_insumo');
$table->timestamps();
//relacion
$table->foreign('id_producto')->references('id')->on('productos');
$table->foreign('id_insumo')->references('id')->on('insumos');
$table->primary(['id_insumo', 'id_producto']);
});
}