Pim
Pim

Reputation: 564

Symfony 'SQLSTATE[HY000] [1049] Unknown database 'symfony''

I'm working on a symfony (2.5.) project with some friend, and we're trying to get out website to work, but somehow it keeps crashing. We've tried updating to a newer version of symfony (2.) and clearing caches, but nothing seems to work.

I believe the source of the problem is that somehow symfony tries to access a 'default' database instead of the database we have specified in the

    parameters.yml

Here is the file:

    parameters:
      database_driver: pdo_mysql
      database_host: 127.0.0.1
      database_port: 3306
      database_name: testdb
      database_user: root
      database_password: null
      mailer_transport: smtp
      mailer_host: 127.0.0.1
      mailer_user: null
      mailer_password: null
      secret: ThisIsVerySecret
      locale: en
      debug_toolbar: true
      debug_redirects: false
      use_assetic_controller: true

Config.yml -> doctrine part

    # Doctrine Configuration
    doctrine:
      dbal:
        driver:   "%database_driver%"
        host:     "%database_host%"
        port:     "%database_port%"
        dbname:   "%database_name%"
        user:     "%database_user%"
        password: "%database_password%"
        charset:  UTF8
      orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        auto_mapping: true

The paginaController :

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;

class PaginaController extends Controller
{

    /**
     * @Template
     */
    public function partnersAction()
    {
        return array();
    }
    /**
     * @Template
     * @Cache(expires="tomorrow")
     */
    public function homeAction()
    {
        return array();
    }

    /**
     * @Template
     */
    public function geschiedenisAction()
    {
        return array();
    }

    /**
     * @Template
     */
    public function profielAction()
    {
        return array();
    }

    /**
     * @Template
     */
    public function reunistenAction()
    {
        return array();
    }

    /**
     * @Template
     */
    public function linksAction()
    {
        return array();
    }
}

We have created an empty database called symfony to see what would happen. Ar first the page loads, but then we would receive the same error when trying to log in (because we still need to access data in the testdb database).

    Base table or view not found: 1146 Table 'symfony.leden' doesn't exist

In this error, it also refers to the symfony-database, instead of the testdb-database.

Is there any possible way to fix this issue, and get symfony to recognize the right database (testdb) and not to access a non-excisting database called symfony?

Upvotes: 1

Views: 10745

Answers (1)

Alvin Bunk
Alvin Bunk

Reputation: 7764

Since you've created the database called symfony, then you need to change this in your parameters.yml file:

database_name: symfony

Or from the command line you could run:

php bin/console doctrine:database:create

This would create the database in your parameters.yml file.

You also need to set the MySQL username and password. The default are 'root' and 'null', so that won't normally work.


EDIT #2 Sounds like a caching issue from the comments feedback. Try this from the command line:

php bin/console cache:clear --env=prod

See if that works.

Upvotes: 4

Related Questions