F
Filament3mo ago
Fonz

Import: Column not found: 1054 Unknown column 'grade' in 'field list'

Hi, I have an import action in a relationship manager, with the following fields:
ImportColumn::make('name')
->requiredMapping()
->rules(['required', 'max:255']),
ImportColumn::make('grade')
->rules(['max:255']),
ImportColumn::make('birthday')
->rules(['date']),
ImportColumn::make('name')
->requiredMapping()
->rules(['required', 'max:255']),
ImportColumn::make('grade')
->rules(['max:255']),
ImportColumn::make('birthday')
->rules(['date']),
Then in resolveRecord(), I check if the record exists (firstOrCreate) and attach to its parent. The value from grade should be saved in the pivot table.
$particpant = Participant::firstOrCreate([
'name' => $this->data['name'],
]);
$grade = $this->data['grade'] ?? null;
$particpant->certificats()->syncWithoutDetaching($this->options['certificatID'], ['grade' => $grade]);

return $particpant;
$particpant = Participant::firstOrCreate([
'name' => $this->data['name'],
]);
$grade = $this->data['grade'] ?? null;
$particpant->certificats()->syncWithoutDetaching($this->options['certificatID'], ['grade' => $grade]);

return $particpant;
If I import name and birthday only, everything works as expected. But as soon as I add grade, I get the following error:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'grade' in 'field list' (Connection: mysql, SQL: update `participants` set `grade` = 10, `participants`.`updated_at` = 2024-03-21 21:02:46 where `id` = 10963)
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'grade' in 'field list' (Connection: mysql, SQL: update `participants` set `grade` = 10, `participants`.`updated_at` = 2024-03-21 21:02:46 where `id` = 10963)
The script tries to add the grade to the participant table when creating a new participant, which does not exist. How to tell it to ignore "grade" when creating a new participant? I tried setting 'birthday' a second parameter, in hope it would then only consider name and birthday. But it does not. Is this even the right way to handle this import action? Thanks
Solution:
I solved it by adding an empty ->fillRecordUsing(function (Participant $participant, string $state) { })...
Jump to solution
1 Reply
Solution
Fonz
Fonz2mo ago
I solved it by adding an empty ->fillRecordUsing(function (Participant $participant, string $state) { })