php - Laravel Migrations - Dropping columns -
i need drop column userdomainname
database table clients
.
at first installed doctrine/dbal
executing composer require doctrine/dbal
followed composer update
, described in documentation.
then created migration want use drop column:
php artisan make:migration remove_user_domain_name_from_clients --table=clients
i added schema::dropcolumn('userdomainname');
down()
method:
<?php use illuminate\support\facades\schema; use illuminate\database\schema\blueprint; use illuminate\database\migrations\migration; class removedomainname extends migration { /** * run migrations. * * @return void */ public function up() { schema::table('clients', function (blueprint $table) { // }); } /** * reverse migrations. * * @return void */ public function down() { schema::table('clients', function (blueprint $table) { schema::dropcolumn('userdomainname'); }); } }
however,
migrating: 2017_08_22_135145_remove_user_domain_name_from_clients migrated: 2017_08_22_135145_remove_user_domain_name_from_clients
after executing php artisan migrate
no column dropped. if execute again nothing migrate.
the down
function used rollbacks, have add dropcolumn
in up
function because action want perform when running migrations.
so, in up
function there should be:
schema::table('clients', function (blueprint $table) { $table->dropcolumn('userdomainname'); });
and in down
function should inverse, add column back:
schema::table('clients', function (blueprint $table) { $table->string('userdomainname'); });
this way, can return point in migrations.
wiki
Comments
Post a Comment