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.
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.phpCommon 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
- Point env.php db host at the CI service over TCP.
- Wait for MySQL to accept connections.
- Run setup:upgrade with
--keep-generatedto avoid recompiling mid-run.
php bin/magento setup:upgrade --keep-generated --no-interactionReset a partially applied schema
For a fresh CI run, start from a clean database so a prior partial upgrade does not leave conflicting tables.
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.