how can I solve laravel php artisan migrate error problem?

how can I solve laravel php artisan migrate error problem?

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Resolving the "Unknown Database" Error in Laravel Migrations

When integrating Facebook login via Laravel Socialite, you might encounter a specific migration failure that halts your database setup process. The error message SQLSTATE[HY000] [1049] Unknown database 'laravel' indicates a fundamental misconfiguration within your .env file rather than a bug in the Socialite package or Laravel itself.

This specific error occurs because the application is attempting to connect to a database named laravel, but that database does not exist on your MySQL server. While this default name often appears in fresh installations, it must be explicitly defined before running migration commands.

Configuring the .env File

The root cause lies in the DB_DATABASE variable inside your project's .env file. If you have cloned a repository without modifying environment variables or if you are following a tutorial that assumes a default setup, this value might still be set to laravel.

To fix this, you must open the .env file and define a valid database name. A common convention is to use the project name or a unique identifier to avoid collisions in shared hosting environments. Update your configuration as follows:

DB_DATABASE=your_project_name

After updating this variable, it is crucial to restart your PHP process manager (like Swoole if you are using Laravel Octane) or simply ensure the web server has reloaded any cached configurations, though for standard development servers like PHP built-in server, a simple save often suffices.

Verifying MySQL Credentials

Even after correcting the database name, the migration command might still fail if the DB_USERNAME and DB_PASSWORD are incorrect or if the specified user lacks permissions to create new databases. Ensure that your credentials match those set up in your local MySQL instance.

If you are using a managed service like MySQL on Windows or a cloud provider, verify that the user has been granted access to the database you just named. You can check existing databases by running:

mysql -u root -p

Once logged in, list the databases to ensure your intended target exists before attempting the migration again. If the database is missing and you have the necessary permissions, you can create it manually using:

CREATE DATABASE your_project_name;

This step ensures that when Laravel runs select * from information_schema.tables, the query succeeds because the schema is present.

Handling Migration State Issues

If you previously ran migrations with an incorrect database name and then switched to the correct one, you might face issues regarding existing migration records. However, since the error Unknown database 'laravel' implies the database was never created, the migrations table simply does not exist yet. Therefore, running the command again should work immediately once the environment is fixed.

Socialite Specific Considerations

When using Laravel Socialite, you will eventually need to run a separate migration to create the users_socialites table after logging in with Facebook for the first time. This migration depends on the main users table existing. Ensure your primary migration runs successfully before attempting social authentication features.

If you are following guides like those from Sitepoint, remember that they often assume a clean slate. If you encounter persistent issues despite correct configuration, check your config/database.php file to ensure it matches your .env settings exactly. Laravel loads the environment variables into this config array at runtime; discrepancies here can lead to subtle failures.

For deeper troubleshooting on social authentication setups or complex database configurations, resources like https://laravelcompany.com can provide additional context on best practices for production-ready Laravel applications.

Our network