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

mouadbz's avatar

php artisan migrate not working

hi devs please i'm facing and issue in my laravel project i created the database and now trying to migrate it but i get this error when i do PHP ARTISAN MIGRATE

the error =>

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

here is my databass.php file

  'mysql' => [
            'driver' => 'mysql',
            'url' => env('DATABASE_URL'),
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'laravel8ecommercedb'),
            'username' => env('DB_USERNAME', 'root'),
            'password' => env('DB_PASSWORD', ''),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'prefix_indexes' => true,
            'strict' => true,
            'engine' => null,
            'options' => extension_loaded('pdo_mysql') ? array_filter([
                PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
            ]) : [],
        ],

here is the .env file


APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:Uzm5lrWw+ZYYVKJ7Tfey30yHidpOMtW7N7LP3F4WWjg=
APP_DEBUG=true
APP_URL=http://laravel.test

LOG_CHANNEL=stack
LOG_LEVEL=debug

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel8ecommercedb
DB_USERNAME=root
DB_PASSWORD=

BROADCAST_DRIVER=log
CACHE_DRIVER=file
FILESYSTEM_DRIVER=local
QUEUE_CONNECTION=sync
SESSION_DRIVER=database
SESSION_LIFETIME=120

MEMCACHED_HOST=127.0.0.1

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_MAILER=smtp
MAIL_HOST=mailhog
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

i'm using MAMP for databass ,and already created the laravel8ecommercedb on it ,, i appreciate any help .

0 likes
4 replies
CorvS's avatar

Try changing your DB_HOST to localhost and see if that works.

mouadbz's avatar

thank you for you reply ,, i did but not worked

Snapey's avatar

Your error indicates you ARE connected to a database but laravel8ecommercedb does not exist.

Are you using homestead or some other virtualisation where the DB available to artisan is not the same one that you are using.

If using homestead, are you running the migrations from within the container or locally?

mouadbz's avatar

no i dont use homestead i'm running locally

Please or to participate in this conversation.