Good morning
I have 2 tables clients and companies, in the second table I am trying to create the relationship but I get an error with the foreign key.
Illuminate \ Database \ QueryException: SQLSTATE [HY000]: General error: 1005 Can not create table
usaly_bd
.#sql-1d3c_2bb
(errno: 150 "Foreign key constraint is incorrectly formed") (SQL: alter tablecompanies
add constraintcompanies_ client_id_foreign
foreign key (client_id
) referencesclients
(company_id
))
This is my clients migration
public function up()
{
Schema::create('clients', function (Blueprint $table) {
$table->increments('client_id');
$table->integer('nuip')->nullable();
$table->string('first_name')->nullable();
$table->string('last_name')->nullable();
$table->integer('phone')->nullable();
$table->integer('cellphone')->nullable();
$table->string('email')->nullable();
$table->string('type_client')->nullable();
$table->timestamps();
});
}
Migration companies
public function up()
{
Schema::create('companies', function (Blueprint $table) {
$table->increments('company_id')->unsigned();
$table->integer('name')->nullable();
$table->string('business_name')->nullable();
$table->string('douments')->nullable();
$table->timestamps();
//Relacion
$table->unsignedInteger('client_id');
$table->foreign('client_id')->references('company_id')->on('clients');
});
}
I appreciate your help