Migrations fail with "duplicate key value violates unique constraint pg_class_relname_nsp_index"

SQLSTATE[23505]: Unique violation: 7 ERROR:  duplicate key value violates unique constraint "pg_class_relname_nsp_index"
DETAIL:  Key (relname, relnamespace)=(migrations_id_seq, 2200) already exists.
(SQL: create table "migrations" ("id" serial not null primary key, ...))
When

Scaffolding a new app into a directory an earlier, unfinished run used — or, on applications scaffolded before kalimera pinned COMPOSE_PROJECT_NAME, into any directory whose name an earlier run used. The MySQL wording is SQLSTATE[42S01] ... Table 'migrations' already exists.

Why it happens

Compose files volumes under the project name as <project>_sail-pgsql, and left to itself it takes that name from the directory. A new scaffold under a project name used before therefore mounts the old database. That volume can hold migrations_id_seq without the migrations table — Laravel's hasTable('migrations') returns false, issues create table migrations (id serial ...), and the implicit sequence collides with the orphan.

Fix

kalimera now handles this itself, in three places. A fresh scaffold pins COMPOSE_PROJECT_NAME=<app>-<hash of the full path> in .env, so ~/work/api and ~/side/api are two projects to docker and can never share a database. Before the first up, SailStart asks docker whether anything already answers to that name — the <project>-<service>-1 containers and the <project>_sail-<service> volumes — which only an earlier run in this very directory can have left, and runs sail down -v only if something does, naming what it is about to remove. Nothing found means nothing touched, which is the usual case; a --continue run keeps its data and is never asked. A resumed run whose .env predates the key keeps the directory-name project its containers already use. If a conflict still gets through, AppFinalize recreates the volume immediately rather than retrying three times first: MigrationFailure retries only when the database could not be reached (SQL class 08, MySQL 2002/2003/2006, or no output at all). Once the server has answered, its verdict will be the same on every attempt.

To clear it by hand:

./vendor/bin/sail down -v && ./vendor/bin/sail up -d --wait && ./vendor/bin/sail artisan migrate

Still stuck? Open an issue with your --log transcript.

All troubleshooting entries