Michael Fayez started a new conversation+100 XP
4mos ago
I need to make a Many to many relationship between Leads table and
1- Tags
2- Gifts
3- Actions
the relationship is working very well between Lead and Tags
but on deployment of my project on Hostinger I have the following error for 2 days didn't removed
SQLSTATE[HY000]: General error: 1005 Can't create table u754910178_sales.lead_gift (errno: 150 "Foreign key constraint is incorrectly formed") (Connection: mysql, SQL: alter table lead_gift add constraint lead_gift_gift_id_foreign foreign key (gift_id) references gifts (id))
this is the Leads migrations
Schema::create('leads', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('phone')->unique();
$table->unsignedBigInteger('statue_id')->nullable();
$table->foreign('statue_id')->references('id')->on('statues')->onDelete('set null');
$table->unsignedBigInteger('category_id')->nullable();
$table->foreignId('user_id')->nullable()->constrained('users')->nullOnDelete();
$table->foreign('category_id')->references('id')->on('categories')->onDelete('set null');
$table->unsignedBigInteger('type_id')->nullable();
$table->foreign('type_id')->references('id')->on('types')->onDelete('set null');
$table->unsignedBigInteger('country_id')->nullable();
$table->foreign('country_id')->references('id')->on('countries')->onDelete('set null');
$table->unsignedBigInteger('city_id')->nullable();
$table->foreign('city_id')->references('id')->on('cities')->onDelete('set null');
$table->unsignedBigInteger('district_id')->nullable();
$table->foreign('district_id')->references('id')->on('districts')->onDelete('set null');
$table->unsignedBigInteger('package_id')->nullable();
$table->foreign('package_id')->references('id')->on('packages')->onDelete('set null');
$table->unsignedBigInteger('source_id')->nullable();
$table->foreign('source_id')->references('id')->on('sources')->onDelete('set null');
$table->text('notes')->nullable();
$table->timestamps();
});
This is the tags
Schema::create('tags', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->timestamps();
});
This is the gifts
Schema::create('gifts', function (Blueprint $table) {
$table->engine = 'InnoDB';
$table->id();
$table->string('name');
$table->timestamps();
});
This is the actions
Schema::create('actions', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->timestamps();
});
Lead Tag // working very well
Schema::create('lead_tag', function (Blueprint $table) {
$table->id();
$table->foreignId('lead_id')->constrained()->onDelete('cascade');
$table->foreignId('tag_id')->constrained()->onDelete('cascade');
$table->timestamps();
});
Lead Gift // not working
Schema::create('lead_gift', function (Blueprint $table) {
$table->id(); // لازم Primary Key
$table->foreignId('lead_id')->constrained()->cascadeOnDelete();
$table->foreignId('gift_id')->constrained()->OnDelete('set null');
$table->timestamps();
});
Lead action //error
Schema::create('lead_action', function (Blueprint $table) {
$table->id();
$table->foreignId('lead_id')->constrained()->cascadeOnDelete();
$table->foreignId('action_id')->constrained()->OnDelete('set null');
$table->timestamps();
});
Please advice and help