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

SchemaDiff throws SchemaException("There is no column ....") since v2.5.5 #2501

Closed
arima-ryunosuke opened this issue Sep 10, 2016 · 6 comments
Assignees
Labels
Milestone

Comments

@arima-ryunosuke
Copy link

code:

<?php
require_once __DIR__ . '/vendor/autoload.php';

$common = array(
    'driver'   => 'pdo_mysql',
    'host'     => '127.0.0.1',
    'user'     => 'user',
    'password' => 'pass',
);

// from Connection
$fromParams = $common;
$fromParams['dbname'] = 'test1';
$fromConn = \Doctrine\DBAL\DriverManager::getConnection($fromParams);

// to Connection
$toParams = $common;
$toParams['dbname'] = 'test2';
$toConn = \Doctrine\DBAL\DriverManager::getConnection($toParams);

// create dummy table
$fromConn->exec('
CREATE TABLE IF NOT EXISTS t_table (
  pid int(11) NOT NULL,
  PRIMARY KEY (pid)
)');
$toConn->exec('
CREATE TABLE IF NOT EXISTS t_table (
  sid int(11) NOT NULL,
  PRIMARY KEY (sid)
)');

// print sql diff
$fromSchema = $fromConn->getSchemaManager()->createSchema();
$toSchema = $toConn->getSchemaManager()->createSchema();
$diff = \Doctrine\DBAL\Schema\Comparator::compareSchemas($fromSchema, $toSchema);
print_r($diff->toSql($fromConn->getDatabasePlatform()));

v2.5.4 is

[0] => ALTER TABLE t_table DROP PRIMARY KEY
[1] => ALTER TABLE t_table CHANGE pid sid INT NOT NULL
[2] => ALTER TABLE t_table ADD PRIMARY KEY (sid)

but v2.5.5 is

Fatal error: Uncaught exception 'Doctrine\DBAL\Schema\SchemaException' with message 'There is no column with name 'sid' on table 't_table'.' in /path/lib/Doctrine/DBAL/Schema/SchemaException.php on line 86

I would like to append to a "MySqlPlatform.php:702" like a below.

if (!$diff->fromTable->hasColumn($columnName)) {
    continue;
}

refs #2302

@Seb33300
Copy link

Seb33300 commented Sep 12, 2016

Same issue here with an oracle database.

Warning: oci_fetch_all(): ORA-01427: single-row subquery returns more than one row in /vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php on line 290

[Doctrine\DBAL\Schema\SchemaException]
There is no column with name '....' on table '...'.

Since 2.5.5, this query fails:

SELECT c.*,
  (SELECT d.comments
  FROM all_col_comments d
  WHERE d.TABLE_NAME = c.TABLE_NAME
  AND d.COLUMN_NAME  = c.COLUMN_NAME
  ) AS comments
FROM all_tab_columns c
WHERE c.table_name = 'MY_TABLE'
AND c.owner        = 'THE_OWNER'
ORDER BY c.column_name;

On 2.5.4, the query was with INNER JOIN:

SELECT c.*,
  d.comments
FROM all_tab_columns c
INNER JOIN all_col_comments d
ON d.TABLE_NAME    = c.TABLE_NAME
AND d.COLUMN_NAME  = c.COLUMN_NAME
WHERE c.table_name = 'MY_TABLE'
AND c.owner        = 'THE_OWNER'
ORDER BY c.column_name;

Reverting back to 2.5.4 solve the issue.

@webdevilopers
Copy link

Same here using doctrine:migrations:diff. Every @manytomany Join Table generates:

[Doctrine\DBAL\Schema\SchemaException]
There is no column with name 'id' on table '...'.

    /**
     * @ORM\ManyToMany(targetEntity="AppBundle\Entity\Contract", inversedBy="expectedFaults")
     * @ORM\JoinTable(name="expected_faults",
     *      joinColumns={@ORM\JoinColumn(name="fault_id", referencedColumnName="id")},
     *      inverseJoinColumns={@ORM\JoinColumn(name="contract_id", referencedColumnName="id")}
     *      )
     */

@weaverryan
Copy link
Contributor

I can confirm this. In fact, we have a number of users that have been hitting this in our ManyToMany tutorial (https://knpuniversity.com/screencast/collections/many-to-many-extra-fields#comment-3094129612), so it's definitely legit (but I know these things are complex!).

@ste93cry
Copy link
Contributor

I hit the bug too, and can confirm that the fix provided by @arima-ryunosuke works in my case, which is adding new columsn to the table and then recreate the primary key to use the old columns plus the new ones.

@arima-ryunosuke
Copy link
Author

This issue is fixed at v2.5.13 by #2696

@Ocramius Ocramius added the Bug label Aug 21, 2017
@Ocramius Ocramius added this to the 2.5.13 milestone Aug 21, 2017
@Ocramius Ocramius self-assigned this Aug 21, 2017
@github-actions
Copy link

github-actions bot commented Aug 3, 2022

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

6 participants