jwavess's avatar

Whats up guys, the newbies got another question!

So on the migration video Mr. Jeffery said used the "php artisan migrate" command within his project directory, and he made sure that sqlite was installed. So when I tried it I got this message.

[PDOException]
SQLSTATE[HY000] [2002] No such file or directory

I do have Mysql installed, and sqlite via Homebrew. My default DB is MySQL, if that helps.

Thanks guys! Can't wait to crack this code. ^ ^

0 likes
15 replies
bobbybouwmann's avatar

You need to make sure your .env file contains the following line

DB_CONNECTION=sqlite

Or update the config file named config/database.php with the following

// Around line 29 

'default' => env('DB_CONNECTION', 'sqlite'),

Also make sure the database exists, you can do that my running the following command in the root directory

touch storage/database.sqlite

You can then successfully migrate

coolAngel's avatar

In 5.2 the directory to store your sqlite db changed from the storage to database.

jwavess's avatar

@bobbybouwmann Could I just do touch database/database.mysql

"database/database" and not "storage/database" Since @coolAngel said so

Also my .env file currently has for the DB_DATABASE=homestead

Dose this mean I also need to go into the Homestead yaml file and add the database I am trying to touch there as well?

bobbybouwmann's avatar

Just change the directory, that is fine.

You don't have to do anything with your Homestead yaml file since sqlite is a file database. Creating the file and pointing the application to it is enough ;)

1 like
jwavess's avatar

@bobbybouwmann Awesome! Last question, which directory should be changed, if I'm using vagrant/homestead.

'default' => env('DB_CONNECTION', 'mysql') to 'default' => env('DB_CONNECTION', 'homestead')

or

DB_DATABASE=homestead to DB_DATABASE=mysql

bashy's avatar

DB_CONNECTION env var relates to the connection name in your config/database.php file. There's an array of them.

Also set your DB_HOST to 192.168.10.10

1 like
jwavess's avatar

I wish I could attach a photo. So after some "Thinking" I've come to the conclusion that it should be set up like this.

DB_HOST=127.0.0.1:2222 DB_DATABASE=homestead DB_USERNAME=vagrant DB_PASSWORD=/Users/imclockedout/.ssh/id_rsa

Since when I "vagrant up"

my ssh address, user name, and auth method all match that. Thats also how my SFTP connection is set. And "homestead" is the only database shown in the yaml file, under databases.

jwavess's avatar

so if its set up like this now.

APP_ENV=local APP_DEBUG=true APP_KEY=31w6AcG8ogUmA1XjWdY1SDnGT7Fp9uIK

DB_HOST=localhost DB_DATABASE=homestead DB_CONNECTION=mysql DB_USERNAME=homestead DB_PASSWORD=secret

CACHE_DRIVER=file SESSION_DRIVER=file QUEUE_DRIVER=syncs

REDIS_HOST=localhost REDIS_PASSWORD=null REDIS_PORT=6379

MAIL_DRIVER=smtp MAIL_HOST=mailtrap.io MAIL_PORT=2525 MAIL_USERNAME=null MAIL_PASSWORD=null MAIL_ENCRYPTION=null

what exactly do I need to change. I am using virtualbox/vagrant/homestead not MAMP.

Pendo's avatar
Pendo
Best Answer
Level 10

Looks like you're confusing two things. When using homestead it's pretty simple.

When you start your homestead server (homestead up), the databases that are set in your Homestead.yaml file are being created. You must specify the database names in this file in order to have them available in your virtual environment. If you then create a new project your can simply use these credentials:

DB Server: localhost
DB Username: homestead
DB Password: secret
DB Name: homestead (or any other database made in Homestead.yaml)

If you want to use (php artisan migrate), make sure you've SSH'ed into your server (homestead ssh). It does not work as long as you are using the Terminal on your local machine, you must be inside homestead ssh.

On the other hand, you're talking about SQLite, in order for this to work you touch the file once so it gets created. You set your database driver to sqlite and then point the database file to the one you just touched. I haven't used SQLit so far, but I think you must also be inside homestead ssh to use the (php artisan migrate) command.

The above is basic stuff explaind in a few videos here. Sounds like you need to get back to basics to clear some things up for yourself.

1 like
jwavess's avatar

Awesome @Pendo. It worked. I was unaware of having to be in the SSH in order for it to work. Seriously THANK YOU!

bashy's avatar

@jwavess @Pendo You can run database commands from either local or VM as long as you set the DB_HOST to 192.168.10.10 (or your VM LAN IP).

Pendo's avatar

@bashy thanks, did not know that! But as I'm used to SSH'ing my homestead environment I'll stick to that!

P.S. @jwaves: make sure to use "homestead suspend" (or homestead halt) and "homestead up" instead of "homestead destroy". When using homestead destroy your database gets destroyed aswel. Of course you can set up your DB with migrations easily, but in my case I lost some dummy data a few times as I wasn't using seeders.

bashy's avatar

@Pendo I hardly ever SSH into the VM, it's a waste of time :P

Also, homestead commands have now been removed and do not work.

Pendo's avatar

I guess I'm on an older version then @bashy? It works fine for now, I'll wait with playing around until the current project is finished.

Brace myself, deadlines are coming ;)

Please or to participate in this conversation.