© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
9 replies
ffffer.

RelationManager select relationship with multiple(), Duplicate entry on update

Hi, the following code in a RelationManager:

public function form(Form $form): Form
    {
        return $form
            ->schema([
                Forms\Components\Section::make()
                ->schema([
                    Forms\Components\Select::make('domains')
                        ->relationship('domains','domain')
                        ->multiple()
                        ->preload(),
public function form(Form $form): Form
    {
        return $form
            ->schema([
                Forms\Components\Section::make()
                ->schema([
                    Forms\Components\Select::make('domains')
                        ->relationship('domains','domain')
                        ->multiple()
                        ->preload(),


With a belongsToMany from both Models to each other. When creating, there is no problem, but when updating and add more domains, I get:

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '1' for key 'assets_content_domain.PRIMARY'
insert into
assets_content_domain
assets_content_domain
(
assets_content_id
assets_content_id
,
domain_id
domain_id
) values (1, 2)

Shouldn't it automatically manage that the record I am updating already exists? It's a bug?

Thanks
Solution
Ahh I see you have a primary key set on assets_content_id and you are setting it wrong for a composite primary key. Try:



$table->primary(['assets_content_id', 'domain_id']);
$table->primary(['assets_content_id', 'domain_id']);
Jump to solution
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

RelationManager problem with duplicate relationship
FilamentFFilament / ❓┊help
2y ago
Multiple clicks create duplicate entry
FilamentFFilament / ❓┊help
2y ago
Multiple Select with BelongsToMany relationship
FilamentFFilament / ❓┊help
3y ago
How to get the current relationship entry on a RelationManager action?
FilamentFFilament / ❓┊help
3y ago