Symfony 2 - 在Id之后向Symfony中的现有实体添加一列

时间:2015-12-30 13:36:17

标签: php mysql symfony doctrine-orm

我使用 DoctrineMigrationsBundle 在数据库中添加表和列。 现在我的问题是如何将现有列移动到表中的另一个位置,或者如果它创建新列,立即指定它所在的位置不在结束表上。

    /**
     * @param Schema $schema
     */
    public function up(Schema $schema)
    {
        // this up() migration is auto-generated, please modify it to your needs
        $table = $schema->getTable('page_content');
        $table->changeColumn('sequence', array(
            'after' => 'id' // - hire I don't know how do this? 
        ));
        $table->addIndex(array('sequence'));
    }

1 个答案:

答案 0 :(得分:3)

您可以执行所需的直接SQL:

CREATE TABLE `owned_games` (
    `user_id` INT(11) NOT NULL,
    `game_id` INT(11) NOT NULL,
    INDEX `FK_owned_games_users` (`user_id`),
    INDEX `FK_owned_games_games` (`game_id`),
    CONSTRAINT `FK_owned_games_games` FOREIGN KEY (`game_id`) REFERENCES `games` (`game_id`) ON UPDATE CASCADE ON DELETE CASCADE,
    CONSTRAINT `FK_owned_games_users` FOREIGN KEY (`user_id`) REFERENCES `users` (`user_id`) ON UPDATE CASCADE ON DELETE CASCADE
)

供参考,请参阅How to move columns in a MySQL table