Symfony Doctrine SQLSTATE 42S02 Base Table or View not found

393 Views Asked by At

I create a Table with Doctrine using this in a Symfony Bundle class:

<?php

namespace Acme\Bundle\TranslationMessagesProducerBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 *
 * @ORM\Entity
 * @ORM\Table(name="acme_translation_config")
 *
 */
class AcmeTranslationMessagesProducerEntity{
    
    /**
     * id - for doctrine
     * @ORM\Column(type="integer")
     * @ORM\Id()
     * @var integer
     */
    private $id;
    
    /**
     * enabled
     * @ORM\Column(type="boolean")
     * @var mixed
     */
    private $enabled;

    public function getId(){
        return $this->id;
    }
    public function getEnabled(){
        return $this->enabled;
    }

}

and this table is existing after running php bin/console doctrine:schema:update --force i can verify it is existing by querying php bin/console doctrine:query:sql "Select * From acme_translation_config or also run: php bin/console doctrine:query:sql "Select * From akeneo_pim.acme_translation_config

Doctrine also recognizes it, verified by running: php bin/console doctrine:mapping:info with result:

Found 58 mapped entities: .... 
Acme\Bundle\TranslationMessagesProducerBundle\Entity\AcmeTranslationMessagesProducerEntity

However if i try to get a object from this table like this:

 $em = $this->getDoctrine()->getManager();
 $config = $em->getRepository(AcmeTranslationMessagesProducerEntity::class)->find(1);

i get the fail:

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'akeneo_pim.acme_translation_config' doesn't exist

How could one resolve this?

1

There are 1 best solutions below

0
Sami On

Replace this

/**
 *
 * @ORM\Entity
 * @ORM\Table(name="acme_translation_config")
 *
 */

By this :

/**
 *
 * @ORM\Entity(repositoryClass="App\Repository\AcmeTranslationMessagesProducerEntityRepository")
 * @ORM\Table(name="acme_translation_config")
 *
 */

And check AcmeTranslationMessagesProducerEntityRepository.php exists

PS : You should follow the naming rules by not adding "Entity" to your class name : AcmeTranslationMessagesProducer is better than AcmeTranslationMessagesProducerEntity