Eddie D's avatar

Migrate new test DB => Database(x) does not exist

I've been developing tests in my "production" mysql database(app is unreleased) and realize I should have a separate test database so setting one up now. I'm following the Laracast on how to set up a test sqlite database, but it's not working I'm getting the error:

eddie@production:~/projects/production2.0$ php artisan migrate --database=sqlite_testing
**************************************
*     Application In Production!     *
**************************************
 Do you really wish to run this command? (yes/no) [no]:
 > yes


   Illuminate\Database\QueryException 

  Database (production) does not exist. (SQL: PRAGMA foreign_keys = ON;)

  at vendor/laravel/framework/src/Illuminate/Database/Connection.php:703
    699▕         // If an exception occurs when attempting to run a query, we'll format the error
    700▕         // message to include the bindings with SQL, which will make this exception a
    701▕         // lot more helpful to the developer instead of just the database's errors.
    702▕         catch (Exception $e) {
  ➜ 703▕             throw new QueryException(
    704▕                 $query, $this->prepareBindings($bindings), $e
    705▕             );
    706▕         }
    707▕     }

      +35 vendor frames 
  36  artisan:37
      Illuminate\Foundation\Console\Kernel::handle()
eddie@production:~/projects/production2.0$ 

Note: the name of my production database is production. I have my APP_ENV set to production as I'm developing an API and want responses to match what I'll see when released...

I touched a file for the DB and permissions look OK:

eddie@production:~/projects/production2.0$ ls -l database/testing.sqlite 
-rw-rw-r-- 1 eddie eddie 0 Apr 19 06:42 database/testing.sqlite

My config/database.php is as follows:

        'sqlite_testing' => [
            'driver' => 'sqlite',
            'url' => env('DATABASE_URL'),
            'database' => env('DB_DATABASE', database_path('testing.sqlite')),
            'prefix' => '',
            'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
        ],

Please note I'm running Laravel 8.6.4, and the video is for 5.5, maybe something changed? Any pointers would be greatly appreciated!

0 likes
5 replies
tykus's avatar

I'm have my APP_ENV set to production as I'm developing an API and want responses to match what I'll see when released

And APP_ENV=production helps with that how?

Eddie D's avatar

@tykus I thought Laravel adds additional debug info to responses when not in Production(e.g. stack trace).

Eddie D's avatar

@tykus Sorry I shouldn't have mentioned this as I don't think it's related to the problem I'm having of not being able to migrate a brand new sqlite test database... If you have any suggestions as to why I might be getting this error I would really appreciate it. This is my first time setting up an sqlite test DB. I read the docs and watched the Laracast, but suspect I'm missing something simple...

tykus's avatar

@Eddie D I don't know why the --database option would not work; in any case, you can change the DB_CONNECTION env variable for the current command:

DB_CONNECTION=sqlite_testing php artisan migrate

Please or to participate in this conversation.