PHP Phinx是来自 CakePHP 的数据库播种/迁移库。
这将创建一个假用户,但是我将如何创建一个对新用户(即子用户)具有FOREIGN KEY
(或常规 ID 引用)的行?id
<?php
use Phinx\Seed\AbstractSeed;
class UserSeeder extends AbstractSeed
{
public function run()
{
$faker = Faker\Factory::create();
$data = [];
for ($i = 0; $i < 100; $i++) {
$data[] = [
'username' => $faker->userName,
'password' => sha1($faker->password),
'password_salt' => sha1('foo'),
'email' => $faker->email,
'first_name' => $faker->firstName,
'last_name' => $faker->lastName,
'created' => date('Y-m-d H:i:s'),
];
}
$this->insert('users', $data);
}
}