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 .
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 :)
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
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community