Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change column type using laravel migration using Doctrine DBAL gives error

I use Laravel 5.2, Php7, Apache, Windows

my migration file is "2016_03_30_095234_alter_date_update_news_table.php"

class AddSlugUpdateNewsTable extends Migration
{
    /**
     * Run the migrations.
     * php artisan make:migration add_slug_update_news_table
     * @return void
     */
    public function up()
    {
        Schema::table('news', function (Blueprint $table) {
            $table->date('slug')->change();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('news', function (Blueprint $table) {
            $table->dateTime('slug')->change();
        });
    }
}

But after run migrate,

$\> php artisan migrate

gives me this error!

[RuntimeException] Changing columns for table "news" requires Doctrine DBAL; install "doctrine/dbal".

what do i do?

like image 558
Amir Hosseinzadeh Avatar asked Dec 08 '22 23:12

Amir Hosseinzadeh


2 Answers

according to laravel docs. You must install doctrine/dbal first if you are using ->change() function.

Type composer require doctrine/dbal in your terminal

like image 94
Kornelius Kristian Rayani Avatar answered Dec 10 '22 13:12

Kornelius Kristian Rayani


/**
 * Run the migrations.
 * php artisan make:migration alter_date_update_news_table
 * @return void
 */
public function up()
{
    Schema::table('news', function (Blueprint $table) {
        $table->dropColumn('date');
    });
    Schema::table('news', function (Blueprint $table) {
        $table->date('date')->after('image');
    });        
}

/**
 * Reverse the migrations.
 *
 * @return void
 */
public function down()
{
    Schema::table('news', function (Blueprint $table) {
        $table->dropColumn('date');
    });
    Schema::table('news', function (Blueprint $table) {
        $table->dateTime('date')->after('image');
    });  
}
like image 22
Amir Hosseinzadeh Avatar answered Dec 10 '22 13:12

Amir Hosseinzadeh