Update models and migrations
Add optional fields or relationships to existing tables while keeping their rows.
▶ Watch the demoOn this page
Add a field
- Stop the API with s, then press m.
- Choose the model and Add an optional field (add optional field).
- Enter
nickname, choose Short text (255 characters), then confirm the options. - Select Finish and generate, review the SQL and confirm.
Miblo generates an ALTER TABLE migration and Rust changes. Existing rows receive NULL when the migration is applied.
miblo edit User 'nickname:string?' --dry-run
miblo edit User 'nickname:string?' --yesFor a relationship, choose Add an optional relationship and the target model. Deletion rules apply here too.
Apply the migration
- The database status becomes Database update required (database update required).
- Press b → Apply migrations (apply migrations), then confirm.
- Wait for Migrations up to date, then start with r.
Editing a model does not automatically apply its migration, including with SQLite. Starting the generated API also applies pending migrations.
miblo db migrate
miblo runKeep already applied migration files unchanged.
Your code changes
Miblo merges generated code with your edits. A conflict stops the operation before writing. Existing handlers and services in the current architecture remain unchanged when adding a field.
Replaced files are copied to .miblo/backups/. These are source and metadata backups, not database backups.
Supported changes
| Automated | Implement in your project |
|---|---|
| Add an optional field, possibly unique. | Rename, remove or change a column type. |
| Add an optional relationship. | Change an existing relationship or make a field required. |
Additions preserve existing rows. Miblo does not choose backfill values for them.