Estou tentando adicionar uma chave estrangeira nessa tabela com o seguinte bloco de código
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();
});
}
Mas estou recebendo a seguinte mensagem:
[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
As tabelas que estou tentando associar existem e com as repectivas chaves primarias autoincremento.