This question already has answers here:
MySQL Creating tables with Foreign Keys giving errno: 150 (20 answers)
Closed last year.
This post was edited and submitted for review 8 hours ago.
I'm working with Laravel8. I have two tables contact_lists
and contacts
I contact_lists
have many contacts
.
Here is my migration code for generation of foreignKey contstraints on contact_lists
public function up()
{
Schema::create('contacts', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('user_id');
$table->foreignId('contact_list_id')->nullable()->constrained()->onDelete('cascade');
$table->string('first_name');
$table->string('last_name');
$table->string('phone');
$table->longText('organization')->nullable();
$table->longText('note')->nullable();
$table->timestamps();
});
}
But I don't know why foreign key is not generating.
1条答案
按热度按时间pcww981p1#
Laravel use
MyISAM
as default mysql storage engine. So make sure in config/database/'engine' => 'InnoDB'
Default:
Updated: