DBML to YAML
dbdiagram:import — Import DBML and generate YAML
Generate a YAML schema file from an existing DBML (Database Markup Language) file. This is useful when you've designed your database schema in dbdiagram.io and want to generate the YAML configuration.
Signature:
php artisan dbdiagram:import
{--file= : Path to the DBML file}
{--output= : Path to the output YAML file}
Options:
--file=path/to/file.dbml— Input DBML file (default:module/dbdiagram.dbml)--output=path/to/output.yaml— Output YAML file (default:module/models.yaml)
Examples:
# Import with defaults
php artisan dbdiagram:import
# Import from custom DBML file
php artisan dbdiagram:import --file=schemas/database.dbml
# Import and save to custom location
php artisan dbdiagram:import \
--file=exports/schema.dbml \
--output=module/models-new.yaml
Features:
- Automatically converts DBML table definitions to YAML format
- Detects and maps relationships (belongsTo, hasMany)
- Handles foreign keys and converts them to
foreignIdfields - Preserves unique constraints, nullable fields, and default values
- Generates compact relation format
- Prompts before overwriting existing YAML files
Workflow:
- Design your database schema at dbdiagram.io
- Export/copy the DBML code
- Save it to a
.dbmlfile - Run
php artisan dbdiagram:import - Review the generated YAML file
- Run
php artisan module:generateto create your modules