Howard
Howard

Reputation: 3758

When using Laravel migrations how do I chose the database?

How do I chose the database that I'd like to do the migration? 'users' is the table. How do I select the database that I'd like to use?

This is what I have:

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUsersTable extends Migration {

        /**
         * Run the migrations.
         *
         * @return void
         */
        public function up() {
            Schema::create('users', function($table) {
                $table->increments('id');

                $table->text('email', 50);
                $table->text('username', 20);
                $table->text('password', 60);
                $table->text('password_temp', 60);
                $table->text('code', 60);

                $table->integer('active');
                $table->text('remember_token', 100)->nullable();

                $table->timestamps();
            });
        }

        /**
         * Reverse the migrations.
         *
         * @return void
         */
        public function down() {
            Schema::drop('users');
        }

}

Upvotes: 1

Views: 48

Answers (3)

Howard
Howard

Reputation: 3758

This is how I solved it. I'll leave it here for others.

Schema::connection('mysql_users')->create('users', function($table) {
    $table->increments('id');

    $table->text('email', 50);
    $table->text('username', 20);
    $table->text('password', 60);
    $table->text('password_temp', 60);
    $table->text('code', 60);

    $table->integer('active');
    $table->text('remember_token', 100)->nullable();

    $table->timestamps();
});

Upvotes: 1

ofrommel
ofrommel

Reputation: 2177

The database is configured in app/config/database.php.

Upvotes: 0

Joel Hinz
Joel Hinz

Reputation: 25414

The migrate command uses the databases specified in your app/config/database.php file. I'd imagine the easiest way to use another database is to create a new file in a new folder, e.g. app/config/mynewenv/database.php, change the appropriate database variables in there, and run php artisan migrate --env=mynewenv.

Upvotes: 0

Related Questions