我正在编写一组Phinx迁移,安装应用程序数据库并插入种子。我的前4个迁移文件分别构建了数据库模式(带有外键约束)、触发器、函数和存储过程。我想使用第五个迁移文件来执行所有的种子,这样以后的每个迁移文件都会有种子数据来处理。
我想要一个从Phinx迁移文件的up方法中运行所有应用程序种子的示例。
发布于 2022-10-25 10:07:15
从迁移文件中执行种子器:
public function change()
{
$table = $this->table('migration_test');
$table->addColumn('example', 'string', ['limit' => 10]);
$table->create();
exec('/usr/local/bin/php ./vendor/bin/phinx seed:run --seed=MySeeder');
}另一种从迁移文件运行播种机的方法:
<?php
declare(strict_types=1);
$namespaceDefinition
use $useClassName;
require_once __DIR__ . '/../seeds/SeederName.php';
final class $className extends $baseClassName
{
public function up()
{
(new SeederName())
->setAdapter($this->getAdapter())
->setInput($this->getInput())
->setOutput($this->getOutput())
->run();
}
public function down()
{
// probably truncate
}
}https://stackoverflow.com/questions/70025190
复制相似问题