14

I started learning Laravel just an hour ago and following tutorials.

My settings for database are as follow (File: app/config/database.php):

'default' => 'mysql',

'connections' => array(

    'sqlite' => array(
        'driver'   => 'sqlite',
        'database' => __DIR__.'/../database/production.sqlite',
        'prefix'   => '',
    ),

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

In mySQL on homestead, I already created laraveltest database. I also created migration file in database/migration directory with following code:

public function up()
{
    Schema::create('users', function($table)
    {
        $table->increments('id');
        $table->string('email')->unique();
        $table->string('name');
        $table->timestamps();
    });
}

and migration commands were:

vagrant@homestead:~/Code/Laravel$ php artisan migrate
Migration table created successfully.
Migrated: 2014_08_14_195103_create_users_table

As displayed, table users created but in homestead database, not in laraveltest database. Can someone please tell where I went wrong and how to force laravel to use laraveltest database?

Edit after first comment File: bootstrap/start.php

$env = $app->detectEnvironment(array(

    'local' => array('homestead'),

));
2
  • 1
    How is your environment detection set up? Can you post the relevant bit from your bootstrap/start.php file? Commented Aug 14, 2014 at 21:08
  • @tbuteler edited in question. Commented Aug 14, 2014 at 21:13

3 Answers 3

14

It is most likely an issue with environments. Check that you have a database configuration file in app/config/local/, and check that it has the proper settings.

Sign up to request clarification or add additional context in comments.

Comments

12

If anyone finds this looking for the answer for Laravel 5 or later: It's the same as @camroncade says, but in this case it's your .env file in the project root you want to look at.

1 Comment

Thanks Karin, you saved me an hour. I think you have to run bash init.sh again to re-write .env file from Homestead if you make changes to ~/.homestead/Homestead.yaml
2

I am currently dealing with this issue as well. Changed the .env file numerous times as well as the config.php file. Nothing seemed to work. After having done some deep digging into the framework I have found an acceptable temporary workaround to the problem that does not conflict with ANY of Laravel 5.0.2's Exceptions.

NOTE: I'm currently using Ampps 3.4 with php 7.0.2 phpmyadmin 4.4.15.1 on a Windows 8.1 OS.

Inside of the file "ConnectionFactory.php" (located at "laravel\vendor\laravel\framework\src\Illuminate\Database\Connectors"), scroll down to the public function make located at line 41. Within this function you can do the following after this statement $config = $this->parseConfig($config, $name); which should be on line 43:

$config['database'] = 'Insert the name of your database here';

This change will allow Laravel to continue with its normal process having no negative effect anywhere with the framework or your project. That is until this bug is fixed by the makers of Laravel or the community.

Till then happy coding! =)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.