How to choose a database to migrate to laravel?
Closed due to the fact that it is necessary to reformulate the question so that it was possible to give an objectively correct answer by the participants of rjhdby , Kromster , Denis , Alex , user194374 26 Dec '16 at 16:29 .
The question gives rise to endless debates and discussions based not on knowledge, but on opinions. To get an answer, rephrase your question so that it can be given an unambiguously correct answer, or delete the question altogether. If the question can be reformulated according to the rules set out in the certificate , edit it .
- What is stopping you to see with what database laravel works? - Visman
- Maybe he means that he has several database (physical)? - Orange_shadow
2 answers
There are two ways, but one detail is common:
Config file app / config / database.php
<?php return array( 'default' => 'mysql', 'connections' => array( // Первая база 'mysql' => array( ), // Вторая база 'mysql2' => array( ), ), ); ?> 1st method: In the migration file:
Schema::connection('mysql2')->create('some_table', function($table) { }); 2nd method: php artisan migrate --database=mysql2
Everything is very simple -
If you look at the facade of Schema you will see the method:
public static function connection($name) { return static::$app['db']->connection($name)->getSchemaBuilder(); }So the answer is in the class constructor :
public function __construct(Connection $connection) { $this->connection = $connection; $this->grammar = $connection->getSchemaGrammar(); }Well, the most boring way is to read in the dock :
To specify the connection mode, use the Schema :: connection method:
Schema::connection('foo')->create('users', function($table) { $table->increments('id'); }); And the connection itself should be written in config/database.php
Array connections .
'connections' => [ 'sqlite' => [ 'driver' => 'sqlite', 'database' => env('DB_DATABASE', database_path('database.sqlite')), 'prefix' => '', ], - Well, this is not the right way. --database = mysql2 console doesn't understand - Jonny Manowar
- @JonnyManowar comments you missed) In general, if you start the migration, it will perform them to the base to which is now connected - Vlad
- @JonnyManowar and the way specified by the colleague should also work - check if your connection exists and you are correct, if you have an old version of laravel write
php artisan help migrate- Vlad