Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

icetechy's avatar

php artisan migrate not working

Below is the error I get each time I try to use the " php artisan migrate" in vs code terminal while .env file is open. How can I successfully migrate my db?

Illuminate\Database\QueryException

SQLSTATE[HY000] [1049] Unknown database 'myfirstdb' (SQL: select * from information_schema.tables where table_schema = myfirstdb and table_name = migrations and table_type = 'BASE TABLE')

at vendor/laravel/framework/src/Illuminate/Database/Connection.php:712 708▕ // If an exception occurs when attempting to run a query, we'll format the error 709▕ // message to include the bindings with SQL, which will make this exception a 710▕ // lot more helpful to the developer instead of just the database's errors. 711▕ catch (Exception $e) { ➜ 712▕ throw new QueryException( 713▕ $query, $this->prepareBindings($bindings), $e 714▕ ); 715▕ } 716▕ }

  +33 vendor frames 

34 artisan:37 Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

0 likes
10 replies
tykus's avatar

while .env file is open

How is this relevant?

Unknown database 'myfirstdb'

Do you have a database named myfirstdb in the configured connection?

icetechy's avatar

@tykus I am a newbie to Laravel. never used it before so I try to be as detailed as possible. I don't know how to do this "Do you have a database named myfirstdb in the configured connection?" I set the db, dbusername and password. then set all privileges to the dbusername.

tykus's avatar

@icetechy okay, but you also need to create a database for the application.

sr57's avatar

migrate does not create the db, you have to create it before and define how to access it in your .env

icetechy's avatar

I manually created the db, db_username and password. is there any other way to create db? @sr57

sr57's avatar

@icetechy

You can create it with a script, but manually is Ok for a one shot action.

Are you able to access your db outside of your app (mysql command, ....)?

icetechy's avatar

@sr57 no I am not able to access the db I created. I created the db, user and pass manually in .env file of my app.

icetechy's avatar

@tykus I opened my app using VSCode, clicked on .env file and manually set a db name, db username and password.

icetechy's avatar
icetechy
OP
Best Answer
Level 1

I have fixed the issue by running "CREATE DATABASE myfirstdb;" then ran "php artisan migrate"

Please or to participate in this conversation.