"Unable to open database file" error when trying to load Doctrine Data Fixtures in Symfony

4.4k views Asked by At

I'm using pdo_mysql for prod, stag and dev environments and pdo_sqlite for test environment. The problem is that loading Doctrine Data Fixtures generates unable to open database file error as shown below. I assigned the permissions to cache folder as defined in symfony website and also tried with 777 but no luck.

I'm on MAC OS Yosemite and sqlite3 is enabled in PHP.

PDO drivers mysql, sqlite, dblib, pgsql
SQLite3 module version  0.7-dev
SQLite Library  3.8.8.3

This command creates the database successfully:

MBP:football bc$ php app/console doctrine:schema:update --force --env=test
Updating database schema...
Database schema updated successfully! "9" queries were executed

This command fails:

MBP:football bc$ php app/console doctrine:fixtures:load --no-interaction --no-debug --env=test

  [PDOException]                                     
  SQLSTATE[HY000] [14] unable to open database file 

config_test.yml (both configs won't work)

doctrine:
    dbal:
        driver: pdo_sqlite
        path: %kernel.cache_dir%/default.db
        charset: UTF8

#doctrine:
#    dbal:
#        default_connection: default
#
#        connections:
#            default:
#                driver:  pdo_sqlite
#                path:    %kernel.cache_dir%/default.db
#                charset: utf8

config.yml

doctrine:
    dbal:
        driver:   pdo_mysql
        host:     "%database_host%"
        port:     "%database_port%"
        dbname:   "%database_name%"
        user:     "%database_user%"
        password: "%database_password%"
        charset:  UTF8
    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        naming_strategy: doctrine.orm.naming_strategy.underscore
        auto_mapping: true

UPDATE:

Settings/steps above work fine in Ubuntu so this is a MAC OS related issue. Mac users, any idea why?

2

There are 2 answers

0
BentCoder On BEST ANSWER

As suggested in Symfony website, if you run into a kind of permissions issue, Mac users should use specific permissions on app/cache folder by running commands below:

HTTPDUSER=`ps aux | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\  -f1`
$ sudo chmod +a "$HTTPDUSER allow delete,write,append,file_inherit,directory_inherit" app/cache app/logs
$ sudo chmod +a "`whoami` allow delete,write,append,file_inherit,directory_inherit" app/cache app/logs

Actually this is what causes the problem so to solve this issue run:

rm -Rf app/cache/test/*

and do not assign any permissions to cache/test folder.

0
Kamil On

I had the same issue and solved it by creating a parent directory for database file: database_path: %kernel.root_dir%/data/data.db3, so I've created 'data' directory. And, of course, make shure that all folders a writable by Doctrine. Hope it helps!