mardi 4 septembre 2018

with migration to fill slug with default value

In my Laravel 5.6/PostgreSQL 10.5 application I have 2 tables :

CREATE TABLE public.rt_genres (
    id serial NOT NULL,
    published bool NULL DEFAULT false,
    created_at timestamp NOT NULL DEFAULT now(),
    updated_at timestamp NULL,
    CONSTRAINT rt_genres_pkey PRIMARY KEY (id)
)...

CREATE TABLE public.rt_genre_translations (
    id serial NOT NULL,
    genre_id int4 NOT NULL,
    "name" varchar(100) NOT NULL,
    description text NOT NULL,
    created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    locale varchar(2) NOT NULL,
    CONSTRAINT genre_translations_genre_id_locale_unique UNIQUE (genre_id, locale),
    CONSTRAINT rt_genre_translations_pkey PRIMARY KEY (id),
    CONSTRAINT genre_translations_genre_id_foreign FOREIGN KEY (genre_id) REFERENCES rt_genres(id) ON DELETE CASCADE
)

I need to add slug field in first rt_genres table with migration rule:

    $table->string('slug', 105)->unique();

and got error :

: Unique violation: 7 ERROR:  could not create unique index "genres_slug_unique"                                          
DETAIL:  Key (slug)=(id) is duplicated.")

1)If there is a way to assign in migration some unique default value, like = id ->default('rt_genres.id') ?

2) That would be cool to assign to slug value from public.rt_genre_translations.name as I use "cviebrock/eloquent-sluggable": "^4.5" plugin in my app ? Can I do it ?

Thank you!



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2NOkl98
via IFTTT

Aucun commentaire:

Enregistrer un commentaire