CakePHP和Phinx addForeignKey失败,重复列

时间:2017-02-02 15:54:54

标签: cakephp-3.0 phinx

我正在尝试创建迁移以将外键添加到现有列,它看起来像这样:

    use Migrations\AbstractMigration;

class AddForeignKeyIndexToPoints extends AbstractMigration
{
    public function up()
    {
        $this->table('points')
            ->addForeignKey('point_type_id', 'point_types', ['id'])
            ->save();
    }

    public function down() {

    }
}

失败了:

    == 20170202112138 AddPointTypeToPoints: migrating
Exception: SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'point_type_id' in [C:\Users\Toby\Documents\projects\map\cake\vendor\robmorgan\phinx\src\Phinx\Db\Adapter\PdoAdapter.php, line 306]
2017-02-03 11:12:01 Error: [PDOException] SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'point_type_id'
Stack Trace:
#0 C:\Users\Toby\Documents\projects\map\cake\vendor\robmorgan\phinx\src\Phinx\Db\Adapter\PdoAdapter.php(306): PDO->exec('ALTER TABLE `po...')
#1 C:\Users\Toby\Documents\projects\map\cake\vendor\robmorgan\phinx\src\Phinx\Db\Adapter\MysqlAdapter.php(408): Phinx\Db\Adapter\PdoAdapter->execute('ALTER TABLE `po...')
#2 C:\Users\Toby\Documents\projects\map\cake\vendor\cakephp\migrations\src\CakeAdapter.php(480): Phinx\Db\Adapter\MysqlAdapter->addColumn(Object(Migrations\Table), Object(Phinx\Db\Table\Column))
#3 C:\Users\Toby\Documents\projects\map\cake\vendor\robmorgan\phinx\src\Phinx\Db\Table.php(625): Migrations\CakeAdapter->addColumn(Object(Migrations\Table), Object(Phinx\Db\Table\Column))
#4 C:\Users\Toby\Documents\projects\map\cake\vendor\cakephp\migrations\src\Table.php(81): Phinx\Db\Table->update()
#5 C:\Users\Toby\Documents\projects\map\cake\vendor\robmorgan\phinx\src\Phinx\Db\Table.php(662): Migrations\Table->update()
#6 C:\Users\Toby\Documents\projects\map\cake\config\Migrations\20170202112138_AddPointTypeToPoints.php(17): Phinx\Db\Table->save()
#7 C:\Users\Toby\Documents\projects\map\cake\vendor\robmorgan\phinx\src\Phinx\Migration\Manager\Environment.php(117): AddPointTypeToPoints->up()
#8 C:\Users\Toby\Documents\projects\map\cake\vendor\robmorgan\phinx\src\Phinx\Migration\Manager.php(309): Phinx\Migration\Manager\Environment->executeMigration(Object(AddPointTypeToPoints), 'up')
#9 C:\Users\Toby\Documents\projects\map\cake\vendor\robmorgan\phinx\src\Phinx\Migration\Manager.php(285): Phinx\Migration\Manager->executeMigration('default',Object(AddPointTypeToPoints), 'up')
#10 C:\Users\Toby\Documents\projects\map\cake\vendor\robmorgan\phinx\src\Phinx\Console\Command\Migrate.php(113): Phinx\Migration\Manager->migrate('default', NULL)
#11 C:\Users\Toby\Documents\projects\map\cake\vendor\cakephp\migrations\src\ConfigurationTrait.php(165): Phinx\Console\Command\Migrate->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#12 C:\Users\Toby\Documents\projects\map\cake\vendor\cakephp\migrations\src\Command\Migrate.php(58): Migrations\Command\Migrate->parentExecute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#13 C:\Users\Toby\Documents\projects\map\cake\vendor\symfony\console\Command\Command.php(255): Migrations\Command\Migrate->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#14 C:\Users\Toby\Documents\projects\map\cake\vendor\symfony\console\Application.php(829): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#15 C:\Users\Toby\Documents\projects\map\cake\vendor\symfony\console\Application.php(191): Symfony\Component\Console\Application->doRunCommand(Object(Migrations\Command\Migrate), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#16 C:\Users\Toby\Documents\projects\map\cake\vendor\symfony\console\Application.php(122): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#17 C:\Users\Toby\Documents\projects\map\cake\vendor\cakephp\migrations\src\Shell\MigrationsShell.php(98): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput))
#18 [internal function]: Migrations\Shell\MigrationsShell->main('migrations', 'migrate')
#19 C:\Users\Toby\Documents\projects\map\cake\vendor\cakephp\cakephp\src\Console\Shell.php(466): call_user_func_array(Array, Array)
#20 C:\Users\Toby\Documents\projects\map\cake\vendor\cakephp\migrations\src\Shell\MigrationsShell.php(130): Cake\Console\Shell->runCommand(Array, true, Array)
#21 C:\Users\Toby\Documents\projects\map\cake\vendor\cakephp\cakephp\src\Console\ShellDispatcher.php(227): Migrations\Shell\MigrationsShell->runCommand(Array,true, Array)
#22 C:\Users\Toby\Documents\projects\map\cake\vendor\cakephp\cakephp\src\Console\ShellDispatcher.php(182): Cake\Console\ShellDispatcher->_dispatch(Array)
#23 C:\Users\Toby\Documents\projects\map\cake\vendor\cakephp\cakephp\src\Console\ShellDispatcher.php(128): Cake\Console\ShellDispatcher->dispatch(Array)
#24 C:\Users\Toby\Documents\projects\map\cake\bin\cake.php(34): Cake\Console\ShellDispatcher::run(Array)
#25 {main}

Phinx docs中至少有一个例子让我相信这应该有用,但我无法理解 - 我做错了什么?

0 个答案:

没有答案