强制更新数据库

时间:2016-12-30 06:19:24

标签: php symfony

在计算机中安装我的应用程序后,我需要插入好的(StatusGoodEntity)默认状态。 如何使用Symfony 2.8 + Doctrine? 我尝试使用DoctrineFixturesBundle,但它在插入数据之前清除数据库。 我已经有了生产数据库,我的新业务逻辑需要在数据库中使用默认数据,在插入之前我无法清除它。

我如何使用Yii 2:

class m150101_185401_create_news_table extends Migration
{
    public function safeUp()
    {
        $this->createTable('good_status', [
            'id' => $this->primaryKey(),
            'title' => $this->string()->notNull(),
            'code' => $this->integer(),
        ]);

        $this->insert('good_status', [
            'title' => 'waiting',
            'code' => 'default',
        ]);

        $this->insert('good_status', [
            'title' => 'closed',
            'code' => 'closed',
        ]);

        $this->insert('good_status', [
            'title' => 'preparing',
            'code' => 'preparing',
        ]);
    }

    ...
}

之后我知道默认状态的ID,我可以肯定它可以使用。

0 个答案:

没有答案
相关问题