11

This might be repeated question. But I had no luck with previous answers

I just git clone a laravel project. Now I tried to do php artisan migrate. It returns the below error.

[InvalidArgumentException]   
Database [] not configured.

and

migrate [--bench[="..."]] [--database[="..."]] [--force] [--path[="..."]] [--package[="..."]] [--pretend] [--seed]

my app/config/database.php is like this:

    'mysql' => array(
        'driver'    => 'mysql',
        'host'      => 'localhost',
        'database'  => 'upgrade',
        'username'  => 'root',
        'password'  => 'root',
        'charset'   => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix'    => '',
    ),

I do create the upgrade database in mysql.

could anyone tell me what I'm doing incorrectly?

thanks in advance.

m2j
  • 1,152
  • 5
  • 18
  • 43
  • Could you please run `php artisan env` to see what the enviroment is? – Bogdan Jul 21 '15 at 20:00
  • Which operation system do you use? – Fatih Kahveci Jul 21 '15 at 20:53
  • do you have a database-user 'root' with a password of 'root'? – Andrew Mack Jul 21 '15 at 21:14
  • Check if the variables aren't being overwritten somewhere - the database[] might mean that that variable is changed to blank somewhere? – Mhluzi Bhaka Jul 22 '15 at 00:12
  • 1
    Environment is set in the `.env` file. – Bogdan Jul 22 '15 at 14:11
  • I had a similar problem with Database [mysql] not configured. If I ran php artisan cache:clear or config:cache I would get the same error. I solved it by going into laravel/bootstrap/cache and deleting the config.php file that was there, and then running the above commands again. I believe it was a file permission error that was preventing the cached config.php file from actually being cleared. – Scotch Design Nov 22 '19 at 05:11
  • 1
    For me the issue was `DB_CONNECTION` set incorrectly for PostgreSQL, it should be `pgsql` – Mint Mar 08 '21 at 06:56

4 Answers4

11

I had the same issue. I have cloned the L5.1 project from GIT and i performed

composer install 
composer update 

and also configured DB details in .env (by default .env is not present so i took the copy of .env.example and renamed as .env). After that if tried to run

 php artisan migrate

I got the same exception like as @users4393829 mentioned. I tried follow commands to find and set the database.

 php artisan tinker
 >>> Config::get('database.connections.mysql.database');
 >>>null
 >>>Config::set('database.connections.mysql.database','homesteaed');
 >>>Config::get('database.connections.mysql.database');
 >>>homesteaed

After doing all this things i found that there is no database.php file so i have placed it in the 'config' folder and ran the migration it works. Please make sure that you have any config files is git ignored in your project.

siva
  • 315
  • 2
  • 11
3

Another solution which worked is to cache config: php artisan config:cache like here

4givN
  • 2,936
  • 2
  • 22
  • 51
1

Just remove .env file and put new to replace

0

I had the same problem, turns out the .env that shipped with the framework defaulted the DB_HOST to localhost and had DB_PORT set.

Changed the host to the FQDN of the machine and it worked fine. I'm guessingif you're connecting to localhost it expects a socket and not a port.

jwh
  • 73
  • 1
  • 6