I have 2 tables and when I try to migrate return to me this error:
General error: 1005 Can't create table
usee_anbari
.#sql-473_21177
(errno: 150 "Foreign key constraint is incorrectly formed") (SQL: alter tablecompanies
add constraintcompanies_access_id_foreign
foreign key (access_id
) referencesaccesses
(id
) on delete cascade)
this is my tables:
public function up()
{
Schema::create('companies', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->text('address');
$table->string('tel1');
$table->string('tel2');
$table->integer('owner');
$table->unsignedBigInteger('access_id');
$table->string('depot_number')->default(2);
$table->timestamps();
$table->foreign('access_id')->references('id')->on('accesses')
->onDelete('cascade');
});
}
and another one :
public function up()
{
Schema::create('accesses', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('type');
$table->string('description');
$table->timestamps();
});
}
what I miss?
accesses
needs to exist before you can reference it - brombeerbigIncrements
isunsignedBigInteger
- lagbox