Orm: ERROR: index "primary" does not exist

Created on 1 Feb 2017  路  18Comments  路  Source: doctrine/orm

Cannot for the life of me find where this DROP INDEX "primary"; is coming from. If I execute each query statement generated from the output of "doctrine:schema:update" everything goes just fine. Symfony 3.2 / Postgres 9.6.1 / Doctrine 2.5 (bundle 1.6)

[Doctrine\DBAL\Exception\DriverException] An exception occurred while executing 'DROP INDEX "primary"': SQLSTATE[42704]: Undefined object: 7 ERROR: index "primary" does not exist
I've searched my code and there's not a single instance of declaring any indexes named primary.

Bug Incomplete Invalid

Most helpful comment

Any update on this? I'm struggling with this problem.

Hello, I had the same problem; I just drop manually the of the entity (database table) you need to change indexes (for example DROP INDEX actual_pk) and then re-run your doctrine update or query.

All 18 comments

This information is not sufficient to provide any help on our side. You'll have to debug further, maybe with a trace and dumping the schema diff object.

Closing as invalid

Dug a little deeper into the issue. I may actually attempt to fix it. Seems like any time a primary key is changed (standard sequence, auto-increment to/from guid) it has an issue fetching the tables metadata (primary keys/index name). I'm going take a stab at this on my own and see if I can come up with the fix

@Ocramius this is definitely a legit bug. It has seemed intermittent for me but I can reproduce it using postgres and a composite key.

  • Add the following entity and create your schema.
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity()
 */
class Test
{
    /**
     * @ORM\Column(type="integer")
     * @ORM\Id()
     */
    protected $id;

    /**
     * @ORM\Column(type="integer")
     * @ORM\Id()
     */
    protected $test;
}
  • Then just remove the second index and run an update.
  • That errors with SQLSTATE[42704]: Undefined object: 7 ERROR: index "primary" does not exist

@johnpancoast can you put this in a test case? I think this might be a DBAL issue though.

@Ocramius sure.

Just came across this as well, postgresql trying to remove a composite key and replace it with a single id column because i needed to add a WHERE conditional to the composite key

@plimpton try making a test case and a new PR with just the failing scenario, if you can

I can reproduce this problem too.

<?php
// bootstrap.php
require_once "vendor/autoload.php";

use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;

$isDevMode = true;

$paths = array(__DIR__.'/entity');
$config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode, null, null, false);

$dbParams = array(
    'driver'   => 'pdo_pgsql',
    'user'     => 'doctrine_test',
    'password' => 'doctrine_test',
    'dbname'   => 'doctrine_test',
    'host'     => 'localhost',
    'charset'  => 'UTF8',
);

$entityManager = EntityManager::create($dbParams, $config);
<?php
// cli-config.php
use Doctrine\ORM\Tools\Console\ConsoleRunner;

require_once 'bootstrap.php';

return ConsoleRunner::createHelperSet($entityManager);
<?php
// entity/user.php
namespace Entity;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 */
class User
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue
     */
   private $sapid;
}
# composer.json
{
    "name": "john/doctrine_test",
    "require": {
        "doctrine/orm": "*"
    }
}

(create postgresql user and database, see dbParams)

composer install
vendor/bin/doctrine orm:schema-tool:update --force

Updating database schema...
Database schema updated successfully! "2" queries were executed

(rename primary key sapid to something else)
vendor/bin/doctrine orm:schema-tool:update --force

Updating database schema...
[Doctrine\DBAL\Exception\DriverException]
An exception occurred while executing 'DROP INDEX "primary"':
SQLSTATE[42704]: Undefined object: 7 ERROR: index "primary" does not exist

vendor/bin/doctrine orm:schema-tool:update --dump-sql

DROP INDEX "primary";
ALTER TABLE "User" RENAME COLUMN sapid TO sapid2;
ALTER TABLE "User" ADD PRIMARY KEY (sapid2);

I have the same bug using Doctrine + Oracle when I'm changing a composite key.

@Ocramius, could you please re-open this issue?

As asked already twice, a test case is needed. The above are examples.

Apologies for not getting to writing this test case, but I have no time at the moment due to other projects (typical story, I know). It's easily re-produceable using those steps iirc. That's the most I can offer at the moment, unfortunately.

I think this is being resolved in https://github.com/doctrine/dbal/pull/2929

Any update on this? I'm struggling with this problem.

Any update on this? I'm struggling with this problem.

Hello, I had the same problem; I just drop manually the of the entity (database table) you need to change indexes (for example DROP INDEX actual_pk) and then re-run your doctrine update or query.

As asked already twice, a test case is needed. The above are examples.

Eh, example would be fresh install of a Symfony project using Postgres. Nothing special needs to be done. It just happens out of the box. Don't even need to drop any indexes. Just make an entity change, generate a migration and there it goes.

https://github.com/doctrine/dbal/pull/3936 is solving the issue (builds were green and tests oo), but is rather a big change and probably should be split in 2 or 3 different pull request.
Anyone willing to help?

Was this page helpful?
0 / 5 - 0 ratings