理论后裁缝



是否有任何方法可以在学说2中制作备份表。

我有一个XML,想每天用Cron工作导入它。首先,我用末端_new创建一个新的模式。

if ($newTables) {
    $tablePastfix = new DoctrineExtensionsTablePastfix('_new');
    $evm->addEventListener(DoctrineORMEvents::loadClassMetadata, $tablePastfix);
    }
    $entityManager = DoctrineORMEntityManager::create($conn, $config, $evm);
    if ($newTables) {
    $tool = new DoctrineORMToolsSchemaTool($entityManager);
    $classes = array (
        $entityManager->getClassMetadata('MyClasses'),
        $entityManager->getClassMetadata('MyClasses'),
        $entityManager->getClassMetadata('MyClasses'),
    );
        $tool->createSchema($classes);
}

之后,我将从XML导入数据。没关系,我重命名表

$dm = DoctrineDBALDriverManager::getConnection($conn);
$sql = "DROP TABLE `mytable_old`;";
$stmt = $dm->query($sql);
$stmt->execute();
$dm = DoctrineDBALDriverManager::getConnection($conn);
$sql = "ALTER TABLE `mytable` RENAME `mytable_old`;";
$stmt = $dm->query($sql);
$stmt->execute();
$dm = DoctrineDBALDriverManager::getConnection($conn);
$sql = "ALTER TABLE `mytable_new` RENAME `mytable`;";
$stmt = $dm->query($sql);
$stmt->execute();

但是当我想再次导入时,我会收到以下错误。。。。。:(

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 1005 Can't create table 'databasename.#sql-220_87' (errno: 121)' in /Applications/MAMP/bin/php/php5.3.14/lib/php/Doctrine/ORM/Tools/ToolsException.php on line 33
PDOException: SQLSTATE[HY000]: General error: 1005 Can't create table 'databasename.#sql-220_87' (errno: 121) in /Applications/MAMP/bin/php/php5.3.14/lib/php/Doctrine/DBAL/Connection.php on line 646
Call Stack:
    0.0011     761296   1. {main}() /path/to/jobs/import.php:0
    0.0014     767024   2. require_once('/path/to/jobs/config.php') /path/to/jobs/import.php:7
    0.0017     770536   3. require_once('/path/to/jobs/bootstrap.php') /path/to/jobs/config.php:3
    0.0020     796264   4. require_once('/path/to/jobs/bootstrap_doctrine.php') /path/to/jobs/bootstrap.php:5
    0.1468    7673040   5. DoctrineORMToolsSchemaTool->createSchema() /path/to/jobs/bootstrap_doctrine.php:53
    1.1216    9445080   6. DoctrineDBALConnection->executeQuery() /Applications/MAMP/bin/php/php5.3.14/lib/php/Doctrine/ORM/Tools/SchemaTool.php:90
    1.1216    9445656   7. PDO->query() /Applications/MAMP/bin/php/php5.3.14/lib/php/Doctrine/DBAL/Connection.php:646
DoctrineDBALDBALException: An exception occurred while executing 'ALTER TABLE doc_consultant_practice_new ADD CONSTRAINT FK_60C69DE344F779A2 FOREIGN KEY (consultant_id) REFERENCES doc_xml_consultant_new (id) ON DELETE CASCADE':
SQLSTATE[HY000]: General error: 1005 Can't create table 'databasename.#sql-220_87' (errno: 121) in /Applications/MAMP/bin/php/php5.3.14/lib/php/Doctrine/DBAL/DBALException.php on line 47
Call Stack:
    0.0011     761296   1. {main}() /path/to/jobs/import.php:0
    0.0014     767024   2. require_once('/path/to/jobs/config.php') /path/to/jobs/import.php:7
    0.0017     770536   3. require_once('/path/to/jobs/bootstrap.php') /path/to/jobs/config.php:3
    0.0020     796264   4. require_once('/path/to/jobs/bootstrap_doctrine.php') /path/to/jobs/bootstrap.php:5
    0.1468    7673040   5. DoctrineORMToolsSchemaTool->createSchema() /path/to/jobs/bootstrap_doctrine.php:53
    1.1216    9445080   6. DoctrineDBALConnection->executeQuery() /Applications/MAMP/bin/php/php5.3.14/lib/php/Doctrine/ORM/Tools/SchemaTool.php:90
DoctrineORMToolsToolsException: Schema-Tool failed with Error 'An exception occurred while executing 'ALTER TABLE doc_consultant_practice_new ADD CONSTRAINT FK_60C69DE344F779A2 FOREIGN KEY (consultant_id) REFERENCES doc_xml_consultant_new (id) ON DELETE CASCADE':
SQLSTATE[HY000]: General error: 1005 Can't create table 'databasename.#sql-220_87' (errno: 121)' while executing DDL: ALTER TABLE doc_consultant_practice_new ADD CONSTRAINT FK_60C69DE344F779A2 FOREIGN KEY (consultant_id) REFERENCES doc_xml_consultant_new (id) ON DELETE CASCADE in /Applications/MAMP/bin/php/php5.3.14/lib/php/Doctrine/ORM/Tools/ToolsException.php on line 33
Call Stack:
    0.0011     761296   1. {main}() /path/to/jobs/import.php:0
    0.0014     767024   2. require_once('/path/to/jobs/config.php') /path/to/jobs/import.php:7
    0.0017     770536   3. require_once('/path/to/jobs/bootstrap.php') /path/to/jobs/config.php:3
    0.0020     796264   4. require_once('/path/to/jobs/bootstrap_doctrine.php') /path/to/jobs/bootstrap.php:5
    0.1468    7673040   5. DoctrineORMToolsSchemaTool->createSchema() /path/to/jobs/bootstrap_doctrine.php:53

有人知道我的错误还是有更好的主意来实现备份表?

看起来您有问题,因为 index 名称重复,前缀表不适合它们的索引。您应该使用其他数据库来用于此类功能,然后可以将其重命名,也可以与打开的两个连接同步数据。

相关内容

  • 没有找到相关文章

最新更新