Support the ongoing development of Laravel.io →
posted 2 years ago
Laravel
public function up()
    {
        Schema::create('payments', function (Blueprint $table) {
            $table->id();
            $table->foreignId('invoice_id')->constrained('invoices')->onDelete('cascade');
            $table->dateTime('payment_date');
            $table->decimal('sub_total', 10, 2);
            $table->string('transaction_id');
            $table->decimal('total_amount', 10, 2);
            $table->decimal('gst', 10, 2);
            $table->string('payment_method');
            $table->uuid('uuid')->unique();
            $table->timestamps();
        });
    } 

SQLSTATE[HY000]: General error: 1005 Can't create table admindashboard.payments (errno: 150 "Foreign key constraint is incorrectly formed") (SQL: alter table payments add constraint payments_invoice_id_foreign foreign key (invoice_id) references invoices (id) on delete cascade)

Please solve this issue .

Last updated by @tvbeek 2 years ago.
0
moderator

Hello @uprightbiswa

Can you check the format of the id field on invoices? If this is different then the new created invoide_id (like int v.s. bigint, signed vs unsigned) it will fail because the types need to be identical.

ps. I have updated your post to make the migration more readable :)

0

I changed the foreign I'd relationship, i set payment I'd in invoice table foreign I'd so problem is solve . Thanks for replying

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.