问题
I have Zend framework script with doctrine 2.
I need to add a new column, what is the correct chronology to go about doing that i.e create column, update entities, run migration etc.
Any help appreciated.
回答1:
If you want manually then create a column in database table and specify that column in you entity class as bellow
/**
* @ORM\Column(type="string") // if column is varchar
*/
protected $title;
if you have already set a CLI for generate entity and database schema file Then use this
-- add New variable ie column name in Entity class
/**
* @ORM\Column(type="string") // if column is Varchar
*/
protected $title;
and execute this command
doctrine orm:schema-tool:update --force update
for more detail about CLI use this link http://wildlyinaccurate.com/useful-doctrine-2-console-commands
来源:https://stackoverflow.com/questions/18568046/add-a-new-column-in-doctrine-2-in-zend-framework