Skip to content

Database & Migrations ​

Migration fails, divergent schema, or connection error.

Symptoms ​

  • Deploy fails with "migration error" or "schema mismatch"
  • App starts but shows errors on specific entities
  • Records missing or fields showing as null after deploy
  • Connection error: "could not connect to database"

Diagnosis checklist ​

  1. Check the deployment log for the exact migration error message
  2. Confirm the environment is running (Dev/Staging/Prod)
  3. Check for pending migrations in Project Settings → Deployment History
  4. Check that environment variables for the database are set correctly

Common causes and solutions ​

Migration fails with a constraint error ​

Cause: adding a required field to an entity that already has records — the migration cannot set a NOT NULL constraint without a default value.

Solution:

  • In the chat or Editor Mode, change the field to optional (not required)
  • OR provide a default value for the field before making it required
  • Deploy again after the fix

Schema mismatch (app errors after deploy) ​

Cause: the deployed code expects schema changes that didn't apply successfully.

  1. Check Deployment History for the failed migration step
  2. Rollback to the last stable version
  3. Fix the underlying issue (see constraint error above)
  4. Redeploy

Records missing after deploy ​

Cause: a migration with a destructive step ran (e.g., column rename or type change with data loss).

  • Rollback immediately using Deployment History
  • Review what changed in the failed deploy
  • For column renames: use Editor Mode to change display labels only (not field names); renaming a field name creates a new column and drops the old one

Connection error ​

Cause: the database credentials or connection string are not set for this environment.

  1. Go to Runtime Settings → Environment Variables
  2. Verify that DATABASE_URL (or the equivalent) is set correctly for this environment
  3. If using a private database: ensure the network allows connections from the Madrix runtime

Migration best practices ​

  • Always test migrations in Dev before promoting to Staging/Prod
  • Avoid making fields required on entities with existing records without a default value
  • Avoid renaming field names — change the display label instead
  • Keep migrations small: one schema change per deploy cycle is easier to debug
  • Monitor the deployment log during each deploy — don't walk away until it completes

© Madrix Software. All rights reserved.