Using Lumen how do I create a migration file? I was using artisan to generate the migration file which looks like
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class UsersCollection extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function($collection)
{
$collection->index('name');
$collection->password('password');
$collection->unique('email');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}
than I try to migrate
php artisan migrate
and I get the following error
[Illuminate\Database\QueryException]
SQLSTATE[3D000]: Invalid catalog name: 1046 No database selected (SQL: create table `migrations` (`migration` varchar(255) not null, `batch` int not null) default ch
aracter set utf8 collate utf8_unicode_ci)
[PDOException]
SQLSTATE[3D000]: Invalid catalog name: 1046 No database selected
it seems like in this case wants to access the Mysql driver, however I have the right config under config/database.php
I do not find a proper description how should be done in this case
What I did:
<?php
use Jenssegers\Mongodb\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateActionsTable extends Migration
{
/**
* The name of the database connection to use.
*
* @var string
*/
protected $connection = 'mongodb';
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::connection($this->connection)
->table('actions', function (Blueprint $collection)
{
$collection->index('name');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::connection($this->connection)
->table('actions', function (Blueprint $collection)
{
$collection->drop();
});
}
}
the just
php artisan migrate
... and it worked.
How do you delete only the index added in the up method, instead of dropping the whole collection?
@Oyelaking Too late for you, but info for future visitors. To remove index just use:
$collection->dropIndex();
Most helpful comment
What I did:
the just
... and it worked.