2017-11-07 4 views
0

私は以下のような移行を作成しています。私はdbをシードする方法を見つけることができませんでした。 似たようなものをお探しですか?移行時に作成したテーブルにデータを挿入するzend framework 3(doctrine/migrations)にデータベースをシードする方法は?

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');  
} 
+0

あなたは、スタンドアロンであなたの移行を実行するための 'config/CLI-config.php'ファイルを使用している、またはあなたの教義-移行の統合のために何か他のものを使用していますか?また、https://github.com/doctrine/data-fixturesを見ましたか? –

答えて

0

一つの方法は、postUp()方法でそれを行うことです。ちょうどあなたのマイグレーションクラスに追加します。

public function postUp(Schema $schema) 
{ 
    $this->connection->insert('user_map', array(
     'user_id' => 1, 
     'relation_id' => 2 
    )); 
    parent::postUp($schema); 
} 
関連する問題