Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

laravel development environment sqlite database does not exist

Trying to use sqlite in development environment. It seems to detect the environment correctly but when I try to migrate to development.sqlite I get exception thrown "database does not exist"

artisan command

php artisan migrate --env=development

bootstrap/start.php

$env = $app->detectEnvironment(array(

    'development' => array('localhost'),

));

app/config/development/database.php

<?php

return array(
    'default' => 'sqlite',

    'connections' => array(
            'sqlite' => array(
            'driver'   => 'sqlite',
            'database' => __DIR__.'/../database/development.sqlite',
            'prefix'   => '',
        )
    )
);

As far as I know laravel is supposed to create the file if it does not exist but since it didn't I tried manually creating the file and still get the exception thrown.

UPDATE: Maybe something not right with the env because the same thing happens if I try ':memory' for the database.

UPDATE 2: I tried running the sample unit test but add to TestCase.php

     /**
     * Default preparation for each test
     *
     */
    public function setUp()
    {
        parent::setUp(); // Don't forget this!

        $this->prepareForTests();
    }

    /**
     * Creates the application.
     *
     * @return Symfony\Component\HttpKernel\HttpKernelInterface
     */
    public function createApplication()
    {
        $unitTesting = true;

        $testEnvironment = 'testing';

        return require __DIR__.'/../../bootstrap/start.php';
    }

    /**
     * Migrates the database and set the mailer to 'pretend'.
     * This will cause the tests to run quickly.
     *
     */
    private function prepareForTests()
    {
        Artisan::call('migrate');
        Mail::pretend(true);
    }

And this too gives the same exception though the testing env is already shipped with laravel. So I'll see if I can find any new issues on that.

like image 563
isimmons Avatar asked Sep 28 '13 17:09

isimmons


2 Answers

I noticed that my database.php file had the following

'sqlite' => [
    'driver' => 'sqlite',
    'database' => env('DB_DATABASE', database_path('database.sqlite')),
    'prefix' => '',
],

I changed it to read the following, and it worked just fine.

'sqlite' => [
    'driver' => 'sqlite',
    'database' => database_path('database.sqlite'),
    'prefix' => '',
],
like image 147
Erica Badu Avatar answered Sep 28 '22 11:09

Erica Badu


Wow, typos and wrong paths.

Copying the sqlite array from config/database.php into config/development/database.php I forgot to change the path to the development.sqlite file from

__DIR__.'/../database/development.sqlite'

to

__DIR__.'/../../database/development.sqlite'

And for the in memory test it should have been

':memory:'

instead of

':memory'
like image 23
isimmons Avatar answered Sep 28 '22 13:09

isimmons