2

我正在尝试使用 phinx 库为名为“Vokuro”的 Phalcon 框架示例项目运行数据库迁移,但出现此错误。文件目录是正确的,所以我不知道为什么会这样。

命令:

C:\xampp\htdocs\vokuro\vendor\bin>phinx.bat status -e development
Phinx by CakePHP - https://phinx.org.

using config file .\phinx.json
using config parser json
using migration paths
 - C:\xampp\htdocs\vokuro\db\migrations
using seed paths
 - C:\xampp\htdocs\vokuro\db\seeds
using environment development
ordering by creation time

In Manager.php line 742:

  Could not find class "CreateEmailConfirmations" in file "C:\xampp\htdocs\vokuro\vendor\bin\..\..\db\migrations\20190825181051_create_email_confirmations.php"

C:\xampp\htdocs\vokuro\db\migrations\20190825181051_create_email_confirmations.php:

<?php
declare(strict_types=1);

namespace Vokuro\Migrations;

use Phinx\Migration\AbstractMigration;

final class CreateEmailConfirmations extends AbstractMigration
{
    public function change(): void
    {
        $table = $this->table('email_confirmations');
        if ($table->exists()) {
            return;
        }

        $table->addColumn('usersId', 'integer')
            ->addColumn('code', 'char', ['limit' => 32])
            ->addColumn('createdAt', 'integer')
            ->addColumn('modifiedAt', 'integer', ['null' => true])
            ->addColumn('confirmed', 'char', ['limit' => 1, 'default' => 'N'])
            ->create();
    }
}

C:\xampp\htdocs\vokuro\vendor\robmorgan\phinx\src\Phinx\Migration\Manager.php:

// convert the filename to a class name
$class = ($namespace === null ? '' : $namespace . '\\') . Util::mapFileNameToClassName(basename($filePath));

if (isset($fileNames[$class])) {
    throw new InvalidArgumentException(sprintf(
        'Migration "%s" has the same name as "%s"',
        basename($filePath),
        $fileNames[$class]
    ));
}

$fileNames[$class] = basename($filePath);

if ($this->getOutput()->getVerbosity() >= OutputInterface::VERBOSITY_DEBUG) {
    $this->getOutput()->writeln("Loading class <info>$class</info> from <info>$filePath</info>.");
}

// load the migration file
$orig_display_errors_setting = ini_get('display_errors');
ini_set('display_errors', 'On');
/** @noinspection PhpIncludeInspection */
require_once $filePath;
ini_set('display_errors', $orig_display_errors_setting);
if (!class_exists($class)) {
    throw new InvalidArgumentException(sprintf(
        'Could not find class "%s" in file "%s"',
        $class,
        $filePath
    ));
}
4

1 回答 1

-1

因为您使用的是自己的配置文件:

using config file .\phinx.json

而不是phinx.php. 该文件位于项目的根目录中。 https://github.com/phalcon/vokuro/blob/master/phinx.php

这个文件里面是paths键,它指定了迁移和种子的命名空间。

于 2020-03-05T12:30:48.253 回答