Doctrine DBAL
  1. Doctrine DBAL
  2. DBAL-377

Rename Table foreignkey not changed

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Invalid
    • Affects Version/s: 2.3
    • Fix Version/s: None
    • Component/s: Schema Managers
    • Security Level: All
    • Labels:
      None

      Description

      if i want to change a tablename the foreign key doesnt change and i get an error

      $config = new Doctrine\DBAL\Configuration();
      $conn = Doctrine\DBAL\DriverManager::getConnection($conn, $config);
      $sm = $conn->getSchemaManager();
      foreach ($sm->listTables() as $table) {
      $fromSchema = $sm->createSchema();
      $toSchema = clone $fromSchema;
      $toSchema->renameTable($table->getName(), str_replace("_new", "", $table->getName()));
      $sql = $fromSchema->getMigrateToSql($toSchema, $conn->getDatabasePlatform());
      foreach ($sql as $query)

      { $conn->query($query); }

      }

      ##################################################
      CREATE TABLE doc_consultant_practice (consultant_id INT NOT NULL, practice_id INT NOT NULL, INDEX IDX_60C69DE344F779A2 (consultant_id), INDEX IDX_60C69DE3ED33821 (practice_id), PRIMARY KEY(consultant_id, practice_id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB
      ALTER TABLE doc_consultant_practice ADD CONSTRAINT FK_60C69DE3ED33821 FOREIGN KEY (practice_id) REFERENCES doc_xml_practice_new (id) ON DELETE CASCADE
      ALTER TABLE doc_consultant_practice ADD CONSTRAINT FK_60C69DE344F779A2 FOREIGN KEY (consultant_id) REFERENCES doc_xml_consultant_new (id) ON DELETE CASCADE
      DROP TABLE doc_consultant_practice_new
      ##################################################
      Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'doc_xml_consultant_new' already exists' in /Applications/MAMP/bin/php/php5.3.14/lib/php/Doctrine/ORM/Tools/ToolsException.php on line 33

      PDOException: SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'doc_xml_consultant_new' already exists in /Applications/MAMP/bin/php/php5.3.14/lib/php/Doctrine/DBAL/Connection.php on line 646

      Call Stack:
      0.0178 766208 1.

      {main}() /PATH/TO/jobs/import.php:0
      0.0430 771936 2. require_once('/PATH/TO/jobs/config.php') /PATH/TO/jobs/import.php:7
      0.0528 775448 3. require_once('/PATH/TO/jobs/bootstrap.php') /PATH/TO/jobs/config.php:3
      0.0623 812680 4. require_once('/PATH/TO/jobs/bootstrap_doctrine.php') /PATH/TO/jobs/bootstrap.php:5
      16.7866 16304048 5. Doctrine\ORM\Tools\SchemaTool->createSchema() /PATH/TO/jobs/bootstrap_doctrine.php:70
      16.8798 16562624 6. Doctrine\DBAL\Connection->executeQuery() /Applications/MAMP/bin/php/php5.3.14/lib/php/Doctrine/ORM/Tools/SchemaTool.php:90
      16.8804 16564080 7. PDO->query() /Applications/MAMP/bin/php/php5.3.14/lib/php/Doctrine/DBAL/Connection.php:646

      Doctrine\DBAL\DBALException: An exception occurred while executing 'CREATE TABLE doc_xml_consultant_new (id INT NOT NULL, name VARCHAR(255) DEFAULT NULL, email VARCHAR(255) DEFAULT NULL, lastCommaFirstName VARCHAR(255) DEFAULT NULL, education LONGTEXT DEFAULT NULL, workHistory LONGTEXT DEFAULT NULL, imageStandard VARCHAR(255) DEFAULT NULL, imageWide VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB':

      SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'doc_xml_consultant_new' already exists in /Applications/MAMP/bin/php/php5.3.14/lib/php/Doctrine/DBAL/DBALException.php on line 47

      Call Stack:
      0.0178 766208 1. {main}

      () /PATH/TO/jobs/import.php:0
      0.0430 771936 2. require_once('/PATH/TO/jobs/config.php') /PATH/TO/jobs/import.php:7
      0.0528 775448 3. require_once('/PATH/TO/jobs/bootstrap.php') /PATH/TO/jobs/config.php:3
      0.0623 812680 4. require_once('/PATH/TO/jobs/bootstrap_doctrine.php') /PATH/TO/jobs/bootstrap.php:5
      16.7866 16304048 5. Doctrine\ORM\Tools\SchemaTool->createSchema() /PATH/TO/jobs/bootstrap_doctrine.php:70
      16.8798 16562624 6. Doctrine\DBAL\Connection->executeQuery() /Applications/MAMP/bin/php/php5.3.14/lib/php/Doctrine/ORM/Tools/SchemaTool.php:90

      Doctrine\ORM\Tools\ToolsException: Schema-Tool failed with Error 'An exception occurred while executing 'CREATE TABLE doc_xml_consultant_new (id INT NOT NULL, name VARCHAR(255) DEFAULT NULL, email VARCHAR(255) DEFAULT NULL, lastCommaFirstName VARCHAR(255) DEFAULT NULL, education LONGTEXT DEFAULT NULL, workHistory LONGTEXT DEFAULT NULL, imageStandard VARCHAR(255) DEFAULT NULL, imageWide VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB':

      SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'doc_xml_consultant_new' already exists' while executing DDL: CREATE TABLE doc_xml_consultant_new (id INT NOT NULL, name VARCHAR(255) DEFAULT NULL, email VARCHAR(255) DEFAULT NULL, lastCommaFirstName VARCHAR(255) DEFAULT NULL, education LONGTEXT DEFAULT NULL, workHistory LONGTEXT DEFAULT NULL, imageStandard VARCHAR(255) DEFAULT NULL, imageWide VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB in /Applications/MAMP/bin/php/php5.3.14/lib/php/Doctrine/ORM/Tools/ToolsException.php on line 33

      Call Stack:
      0.0178 766208 1.

      {main}

      () /PATH/TO/jobs/import.php:0
      0.0430 771936 2. require_once('/PATH/TO/jobs/config.php') /PATH/TO/jobs/import.php:7
      0.0528 775448 3. require_once('/PATH/TO/jobs/bootstrap.php') /PATH/TO/jobs/config.php:3
      0.0623 812680 4. require_once('/PATH/TO/jobs/bootstrap_doctrine.php') /PATH/TO/jobs/bootstrap.php:5
      16.7866 16304048 5. Doctrine\ORM\Tools\SchemaTool->createSchema() /PATH/TO/jobs/bootstrap_doctrine.php:70

        Activity

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Manuel
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: