Skip to content
Latchkey

Magento "bin/magento setup:upgrade" failed in CI

setup:upgrade reconciles installed module versions with the database, applying schema and data changes. It fails when it cannot reach the database, when a declarative schema diff errors, or when a module's setup version is inconsistent with what is recorded.

What this error means

The step fails partway with a SQLSTATE error, "Schema integrity violation", or "Module ... cannot be upgraded", leaving setup_module versions partially applied.

Magento
SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'vendor_module_entity'
already exists, query was: CREATE TABLE `vendor_module_entity` ...
#0 .../Setup/Declaration/Schema/Db/SchemaBuilder.php

Common causes

The database is unreachable or not ready

env.php points at a host or credentials the runner cannot use, or the MySQL service is still starting when upgrade runs.

A declarative schema or data inconsistency

A module's db_schema.xml conflicts with the existing schema, or a partially applied prior run left tables in an inconsistent state.

How to fix it

Confirm the database before upgrading

  1. Point env.php db host at the CI service over TCP.
  2. Wait for MySQL to accept connections.
  3. Run setup:upgrade with --keep-generated to avoid recompiling mid-run.
Terminal
php bin/magento setup:upgrade --keep-generated --no-interaction

Reset a partially applied schema

For a fresh CI run, start from a clean database so a prior partial upgrade does not leave conflicting tables.

Terminal
mysql -h127.0.0.1 -uroot -proot -e "DROP DATABASE magento; CREATE DATABASE magento;"

How to prevent it

  • Start each CI run from a clean, reachable database.
  • Gate setup:upgrade behind a DB readiness check.
  • Keep db_schema.xml consistent with the installed schema.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →