CakePHP 3的Migration插件是Phinx包装器插件,因此可以使用以下
up()方法添加记录:
public function up() { // Save records to the newly created schema}public function down() { // Remove records}例如,你可以使用添加新用户
TableRegistry上
up: -
public function up() { // Save records to the newly created schema $UsersTable = TableRegistry::get('Users'); $user = $UsersTable->newEntity(); $user->name = 'Joe Bloggs'; $user->email = 'joe@example.com'; $UsersTable->save($user);}如果使用,
TableRegistry请不要忘
use CakeORMTableRegistry;了在迁移文件的顶部添加。
对于CakeDC的Migration插件,您可以使用回调在相关迁移文件中插入记录:-
public function after($direction) { if ($direction === 'up') { // Save records to the newly created schema } elseif ($direction === 'down') { // Remove records }}注意:如果您使用的是Postgres驱动程序,则当前存在一个错误,需要一个较小的解决方法才能完成此工作。



