beznez's avatar

Setting up the environment

Hi Laracasts, I will soon be making an API with Lumen and I decided to setup a project on my laptop for some practice before I setup the real project at work. I wanted to get some database interaction so I installed sqlite. I've never used it, but I know mysql and aside that, I just want the drivers to work so that I can interact with it through eloquent. Right now in my .env file, I have this configuration.

DB_CONNECTION=sqlite
DB_FILE=db.sql

When I run php artisan migrate, I get:

 [InvalidArgumentException]  
  Database does not exist.

What other configuration do I need more for sqlite? Also, what do I need for mysql? That's what I'll be using for work.

0 likes
19 replies
mstnorris's avatar

Have you created the database? You need to create a file in the /storage directory.

beznez's avatar

Yes, and it is in the same folder named db.sql. I moved it into the storage folder but I still get the same error.

mstnorris's avatar

Have you edited your config/database.php file? By default the file name is called database.sqlite, not db.sqlite.

'connections' => [

        'sqlite' => [
            'driver'   => 'sqlite',
            'database' => storage_path().'/database.sqlite',
            'prefix'   => '',
        ],
]
beznez's avatar

In Lumen there is no config folder. It is all declared in your .env file. I renamed the file database.sqlite and made all the other necessary changes and I got a different error:

  [PDOException]         
  could not find driver
mstnorris's avatar

Ahh apologies, from the limited docs it says to follow Laravel. I'm checking on that for you now.

beznez's avatar

I tried that but I get the same PDO error.

mstnorris's avatar

Can I see your .env file (remove sensitive data).

Please also let me know where your database.sqlite is now stored.

beznez's avatar

My .env file:

APP_ENV=local
APP_DEBUG=true
APP_KEY=abc123

APP_LOCALE=en
APP_FALLBACK_LOCALE=en

DB_CONNECTION=sqlite
DB_FILE=database.sqlite

DB_DRIVER=sqlite
CACHE_DRIVER=memcached
SESSION_DRIVER=memcached
QUEUE_DRIVER=database

database.sqlite is stored in storage/database.sqlite.

mstnorris's avatar

You need to use:

DB_DATABASE='storage/database.sqlite'
DB_DRIVER=sqlite

Remove DB_CONNECTION and DB_FILE, where did you get those constant names from? I can't see them in the documentation.


Or, just use:

DB_CONNECTION=sqlite

And comment-out all other DB_*

beznez's avatar

They were the constants present from the .env.example that comes with Lumen. I made the changes, but I stil get the same PDO exception.

beznez's avatar

Bump. I wasn't able to do a full test at home. Today, I'll be setting up the Lumen project. What environment variables will I need to setup for mysql?

mstnorris's avatar

Check http://lumen.laravel.com/docs/database

Lumen makes connecting with databases and running queries extremely simple. Currently Laravel supports four database systems: MySQL, Postgres, SQLite, and SQL Server.

You may use the DB_* configuration options in your .env configuration file to configure your database settings, such as the driver, host, username, and password.

Note: In order for your configuration values to be loaded, you will need to uncomment the Dotenv::load() method call in your bootstrap/app.php file.

This last one is important.

bashy's avatar

Could not find driver normally means that either MySQL with PHP support is not enabled or it's using the wrong host.

beznez's avatar

I got it. Thanks for all the help. I changed localhost to 127.0.0.1 and now I'm able to run database migrations. Here's what my .env file looks like for anyone who is interested or may be having the same problem:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=table_name
DB_USERNAME=testing_user
DB_PASSWORD=testing_password
beznez's avatar

Sorry about the confusion. I probably should have explained a little more. At work I'm setting up a project in Lumen. It's the first Lumen project that I've done so I wanted to get my feet wet by making one at home. I didn't want to install mysql and so I tried to use sqlite. I wasn't able to resolve it last night and so now that I'm at work the question is still relevant, but I needed to verify for mysql, not sqlite, since it's a different database here at work. Honestly, I wanted to know how to do both anyway. At work we use mysql but I wanted to know about sqlite as well so that I could make up a quick example at home whenever I need to.

lukee's avatar

I had this issue with postgres. The solution is to run migrations from inside your Vagrant/Homestead box, as it (should) contains all the appropriate drivers. It surely will if you are using Homestead.

So:

homestead ssh
cd path/to/project
artisan migrate


PDO exception will not bother you here.

Please or to participate in this conversation.