3
I am trying to add a foreign key to this table with the following code block
public function up()
{
Schema::create('registros', function (Blueprint $table) {
$table->increments('id');
$table->integer( 'cliente' )->unsigned()->index();
$table->integer( 'item' )->unsigned()->index();
$table->decimal( 'vl_preco',10,2 );
$table->char( 'sn_pago',1 );
$table->integer( 'qt_compra' )->unsigned();
$table->foreign( 'cliente' )->references( 'clientes' )->on('id') ;
$table->foreign( 'item' )->references( 'item' )->on('id') ;
$table->timestamps();
});
}
But I’m getting the following message:
[Illuminate Database Queryexception] SQLSTATE[HY000]: General error: 1215 Cannot add Foreign key Constraint (SQL: alter table
registros
add Constraintregistros_cliente_foreign
Foreign key (cliente
) Referencesid
(clientes
))[Pdoexception] SQLSTATE[HY000]: General error: 1215 Cannot add Foreign key Constraint
The tables I’m trying to associate exist and with the primary keys auto increment repective.
Dude! That’s right... I was blinded oh kkk. Thank you so much!
– adventistaam
If it is the answer of your problem could accept as reply @adventistaam
– novic