F
Filamentβ€’12mo ago
IranMine123

Bulk Deleting on not migrated Tables

Hello I have a Problem, I have a resource on filament that have belongs to a model that does have a "not migrated" table. it means the table created manually or by other applications. the problem is when users select some of records on Table (I mean the table of filament) and then Bulk Deleting them, all records gets Deleted. there are some things to note: - as I said the table not migrated by Laravel and I really can't to that - the table does'nt have ID Column. maybe this thing cause all records gets Deleted. if it is, how I can change it to other Column? I Don't know it's gonna be a bug or something else... but if there is a way to fix, Please tell me how I can fix that. tysm
Solution:
Of course, the delete statement will be "delete from table where primary_key = 'value'". If every row has the same value.......
Jump to solution
9 Replies
WiseWill
WiseWillβ€’12mo ago
I assume the table has a primary key column with some name other than "id". If that is the case, all you might need to do is specify the primary key on the model:
protected $primaryKey = 'pk'; // or whatever it is called
public $timestamps = false; // Probably doesn't have timestamps
protected $primaryKey = 'pk'; // or whatever it is called
public $timestamps = false; // Probably doesn't have timestamps
IranMine123
IranMine123OPβ€’12mo ago
well, i set timestamps = false, but still not working.
WiseWill
WiseWillβ€’12mo ago
Did you define the primary key? That is the important bit. That is how you change it to other Column.
IranMine123
IranMine123OPβ€’12mo ago
yea i already defined that before
WiseWill
WiseWillβ€’12mo ago
That normally works for me. I assume the column you are using contains unique entries, even if it isn't the primary key? A unique key at least?
IranMine123
IranMine123OPβ€’12mo ago
it should be unique?
Solution
WiseWill
WiseWillβ€’12mo ago
Of course, the delete statement will be "delete from table where primary_key = 'value'". If every row has the same value.......
IranMine123
IranMine123OPβ€’12mo ago
well, the primary key of mysql table is other column. should i change the model's primary key to the mysql one? oh it worked!!!!!! TYSM!
WiseWill
WiseWillβ€’12mo ago
πŸ‘
Want results from more Discord servers?
Add your server