migration error
i create new migration to add cascadeondelete() but when i try to run migrations i have this error
SQLSTATE[42000]: Syntax error or access violation: 1091 Can't DROP 'purchases_company_id_foreign'; check that column/key exists (Connection: mysql, SQL: alter table
purchases drop foreign key
purchases_company_id_foreign)
9 Replies
there is what i wrote in my migration
Schema::table('purchases', function (Blueprint $table) {
$table->dropForeign(['company_id']);
$table->dropForeign(['supplier_id']);
$table->dropForeign(['subbrand_id']);
$table->dropForeign(['currency_id']);
$table->foreign('company_id')
->references('id')
->on('purchases')
->cascadeOnDelete();
$table->foreign('supplier_id')
->references('id')
->on('purchases')
->cascadeOnDelete();
$table->foreign('subbrand_id')
->references('id')
->on('purchases')
->cascadeOnDelete();
$table->foreign('currency_id')
->references('id')
->on('purchases')
->cascadeOnDelete();
});
anyonee?This isn't a filament issue and please don't expect a prompt response without paying for someone, but a laravel issue. check the key exists first or try catch.
for each foreign
yep i know and thanks for ur time
what i should wirte in catch?
like what menas
Log here
there is my table btw
which i want to update
It means log here if you want to, else it catches it and lets the rest of the code run. It's basic php. If you are unsure, I advise you google and research how to use php try catch.
Like i have problem that i cant delete rows on my table in my filament app
becouse i have foreignkey error
so i should change this 4 column right?
please anyone help me how i can delete foregin id items ?
im trying to solve this about 2 days 😄
I have told you above.
its not working..
aa wait
i found a solution i think 😄
SQLSTATE[42000]: Syntax error or access violation: 1091 Can't DROP 'purchase_brand_purchase_id_foreign'; check that column/key exists (Connection: mysql, SQL: alter table
purchase_brand drop foreign key
purchase_brand_purchase_id_foreign)
but its exist
5 min ago second table was same error and now its run but now
i have same problem in this table
ah thats works
but migrations run when i refresh migrations
is it possible tu run this migrations without that?
becouse i dont want to lose my data
tf its deleted but when i try to add new i have this error now..
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (
biblusi_purchase.
purchases, CONSTRAINT
purchases_company_id_foreign FOREIGN KEY (
company_id) REFERENCES
purchases (
id) ON DELETE CASCADE)
tf why?
?/