是否存在为现有Doctrine实体添加属性的交互式CLI命令?
Great question—manually adding properties, getters, and setters to Doctrine entities gets old quick, so I totally get why you’re hunting for a CLI shortcut!
Here’s the breakdown of what’s available:
Symfony’s MakerBundle (the go-to solution)
If you’re working in a Symfony project, themake:entitycommand does exactly what you want. It supports interactive updates to existing entities, letting you add single fields without touching the PHP file manually. Here’s how it works:- Run the command:
php bin/console make:entity - When prompted for the "Class name of the entity to create or update", type the name of your existing entity (e.g.,
UserorProduct). - Next, enter the name of the new field you want to add (e.g.,
phoneNumber). - Follow the interactive prompts to set the field type (like
string,integer, ordatetime), length, nullable status, default values, and any other relevant options. - Hit enter when you’re done adding fields, and the command will automatically update your entity class with the new property, getter, setter, and Doctrine mapping annotations.
- Run the command:
Native Doctrine CLI limitations
Out-of-the-box Doctrine doesn’t have a built-in interactive command for adding single fields to existing entities. Thedoctrine:generate:entitycommand is only for creating new entities from scratch, not modifying existing ones.Alternative for non-Symfony projects
If you’re using Doctrine outside Symfony, there aren’t many official interactive CLI tools for this. You could look into third-party packages or write a simple custom script to automate the boilerplate, but these are less polished than Symfony’s MakerBundle.
内容的提问来源于stack exchange,提问作者Mayor of the Plattenbaus

