PHP Development

Use Yii Migrations and Fixtures to Manage Application Data

Manage schema evolution and repeatable test data with Yii migrations and fixtures.

Database changes are part of application releases. Yii migrations provide a versioned way to describe schema changes, while fixtures help tests begin from known data.

Write focused migrations

A migration should make one coherent schema change and include a safe rollback when practical. Review generated SQL for indexes, foreign keys and data transformations. Large table changes may need a staged deployment plan.

Keep data migrations deliberate

Schema changes and bulk data transformations have different risk profiles. For large datasets, use resumable batches and progress tracking rather than a single long-running deployment transaction.

Use fixtures for tests

Fixtures should create only the records needed by a test and should avoid depending on production identifiers. Keep fixture relationships valid and reset test state predictably.

Deployment discipline

Back up the database, test migrations against a production-like copy and verify application compatibility during rollout. Do not assume that a successful migration on an empty database proves safety on a populated one.

Further reading

Share this page Help other developers discover this resource.