B
B
BonBon Slick2018-12-30 23:20:43
Doctrine ORM
BonBon Slick, 2018-12-30 23:20:43

ORMPurger tables not found when they are?

lzakrzewski.com/2016/02/tricks-to-speed-up-databas...
Trick no 2: Purge database instead drop and create

/**
     * Refresh database with fixtures.
     */
    protected function refreshDatabase(): void
    {
        $purger = new ORMPurger($this->getEntityManager());
        $purger->purge();

 // код ниже работает, код выше не находит таблицы,на каждую выкидывает ексепшен что
// таблица не найдена

        // // drop database
        // $schemaTool = new SchemaTool($this->getEntityManager());
        // $schemaTool->dropDatabase();
        //
        // // create database
        // $metadatas = $this->entityManager->getMetadataFactory()->getAllMetadata();
        // if (!empty($metadatas)) {
        //     try {
        //         $schemaTool->createSchema($metadatas);
        //     } catch (\Exception $e) {
        //         dump($e);
        //     }
        // }
        //
        // // load test fixtures
        // $this->refreshFixtures();
    }

An example is for all tables, they are in the database. I checked the connection and everything is ok.
EDoctrine\DBAL\Exception\TableNotFoundException {#4464
  -driverException: Doctrine\DBAL\Driver\PDOException {#4466
    -errorCode: 1
    -sqlState: "HY000"
    #message: "SQLSTATE[HY000]: General error: 1 no such table: pro6pp_postcode_street"
    #code: "HY000"
    #file: "./vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php"
    #line: 43
    -previous: PDOException {#4596
      #message: "SQLSTATE[HY000]: General error: 1 no such table: pro6pp_postcode_street"
      #code: "HY000"
      #file: "./vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php"
      #line: 41
      +errorInfo: array:3 [
        0 => "HY000"
        1 => 1
        2 => "no such table: pro6pp_postcode_street"
      ]

Also tried like this
$conn       = $this->getEntityManager()->getConnection(); // "/tmp/site-db-test.db"
        $conn->exec('DELETE FROM users'); // table exists, but this thorws exception that it does not

Presumably
doctrine:
  dbal:
    driver: pdo_sqlite
    path: /tmp/site-db-test.db // тут нет всех таблиц, а ORMPurger вызывает все что замаплены
    memory: false
    charset: UTF8

$conn       = $this->getEntityManager()->getConnection();
                    $schemaTool = new SchemaTool($this->getEntityManager());
    $schemaTool->createSchema($metadatas);

        dump($conn->exec('SELECT name FROM sqlite_master WHERE type = "table"')); // 0
        die;

Why can't find tables?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question