jldavis76's avatar

Error when trying to do Migrations

I am currently going through the Laravel From Scratch series here on Laracasts, and in episode 6 (I believe??), it begins talking about using Eloquent. I followed the directions for changing database configuration to use sqlite, and I add the database.sqlite file to the database folder. This is all that is specified to do in the video. However, when I try the 'php artisan migrate' command, I get the following error:

    [PDOException]
SQLSTATE[HY000] [2003] Can't connect to MySQL server on '127.0.0.1' (61)

Am I missing a step in the process? It seems it is still trying to connect to MySQL despite the changes I made to the database config file.

Any help is greatly appreciated. Thank you.

0 likes
6 replies
jldavis76's avatar

My .env file reads as such:

APP_ENV=local
APP_DEBUG=true
APP_KEY=base64:dUJjtQsUvjyT1zsHYDYVNUAHygIGMWj4Yu7N4CduAzg=
APP_URL=http://localhost

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

REDIS_HOST=127.0.0.1
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

I see that the DB_CONNECTION still is equal to mysql, is this what is causing it? If so, what does the database config file do?

santigarcor's avatar

I think that's the problem, you have to change your connection to sqlite

jldavis76's avatar

I've done that, and it allowed the migration to go through, and allowed me to insert and retrieve data using artisan tinker. However, when I went to retrieve data in the controller to display, I got this error:

PDOException in Connector.php line 55:
SQLSTATE[HY000] [2003] Can't connect to MySQL server on '127.0.0.1' (61)

Which is the same one I had before. I guess I am just confused as what the point of changing anything in the database config file if it doesn't change the .env file?

moharrum's avatar

Restart your server, clear cache if necessary.

asdasdsa's avatar

remove

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

from env file

Please or to participate in this conversation.