doupi4649 2017-11-07 11:51
浏览 36

如何在zend框架3(doctrine / migrations)中播种数据库?

I'm creating migration like below. I couldn't find a way to seed db. Looking for something similar db:seed in laravel ?

public function up(Schema $schema)
{
    $table = $schema->createTable('user_map');
    $table->addColumn('id', 'integer', ['autoincrement'=>true]); 
    $table->addColumn('user_id', 'integer', ['notnull'=>true]);
    $table->addColumn('relation_id', 'integer', ['notnull'=>true]);
    $table->setPrimaryKey(['id']);
    $table->addOption('engine' , 'InnoDB');       
}
  • 写回答

1条回答 默认 最新

  • dongzhan7253 2017-11-11 21:42
    关注

    One way to insert data in the table created at your migration is to do it in the postUp() method. Just add in your migration class:

    public function postUp(Schema $schema)
    {
        $this->connection->insert('user_map', array(
            'user_id' => 1,
            'relation_id' => 2
        ));
        parent::postUp($schema);
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 r包runway详细安装教程
  • ¥15 Html中读取Json文件中数据并制作表格
  • ¥15 谁有RH342练习环境
  • ¥15 STM32F407 DMA中断问题
  • ¥15 uniapp连接阿里云无法发布消息和订阅
  • ¥25 麦当劳点餐系统代码纠错
  • ¥15 轮班监督委员会问题。
  • ¥20 关于变压器的具体案例分析
  • ¥15 生成的QRCode圖片加上下載按鈕
  • ¥15 板材切割优化算法,数学建模,python,lingo