Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERROR: index "primary" does not exist #6271

Closed
tlorens opened this issue Feb 1, 2017 · 23 comments
Closed

ERROR: index "primary" does not exist #6271

tlorens opened this issue Feb 1, 2017 · 23 comments

Comments

@tlorens
Copy link

tlorens commented Feb 1, 2017

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)

  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.

@Ocramius
Copy link
Member

Ocramius commented Feb 1, 2017

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

@tlorens
Copy link
Author

tlorens commented Feb 10, 2017

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

@johnpancoast
Copy link

johnpancoast commented Mar 11, 2017

@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

@Ocramius
Copy link
Member

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

@johnpancoast
Copy link

@Ocramius sure.

@plimpton
Copy link

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

@Ocramius
Copy link
Member

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

@jrysig
Copy link

jrysig commented Jun 15, 2017

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);

@anacicconi
Copy link

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

@jrysig
Copy link

jrysig commented Jun 22, 2017

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

@Ocramius
Copy link
Member

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

@johnpancoast
Copy link

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.

@simPod
Copy link
Contributor

simPod commented Dec 27, 2017

I think this is being resolved in doctrine/dbal#2929

@simobrazz
Copy link

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

@tchafack
Copy link

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.

@goetas
Copy link
Member

goetas commented Apr 9, 2020

Most probably related to doctrine/dbal#3936

@tlorens
Copy link
Author

tlorens commented Jun 4, 2020

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.

@goetas
Copy link
Member

goetas commented Jun 6, 2020

doctrine/dbal#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?

@f-lombardo
Copy link

The problem is still present (2.14.1). Is there any way to solve it?
Thanks in advance.

@johnpancoast
Copy link

johnpancoast commented Apr 19, 2023

@f-lombardo, maybe check out @tlorens' workaround above.

Until one of us writes a simple test case, the contributors cannot do much. I was super busy when I wrote this and didn't have time to go through doctrine's merge standards and all that at the time. I can't commit time for certain (I'm an awful human) but I'll try to do it unless somebody beats me to it. The test itself should be easy, and can likely just do something similar to this (just my assumption). Once that's written contributors can dig in.

@f-lombardo
Copy link

Thank you @johnpancoast , see doctrine/dbal#6025

@johnpancoast
Copy link

johnpancoast commented May 3, 2023

Glad I could help... well, at least like .5% like 5 years ago :)

@f-lombardo
Copy link

Fixed:
doctrine/dbal#6025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests