69

移行列の種類を$table->string('text');テキスト型に変更する必要があります。いくつかの方法でそれを試みましたが、どれもうまくいきませんでした。1回の移行でそれを行うことは可能ですか? 列をドロップしてから、新しいタイプで再度作成することもできますが、1 回の移行でそれを行うことは可能でしょうか?

4

5 に答える 5

112

新しい移行を作成し、1 つの列タイプのみを変更できます。

public function up()
{
    Schema::table('sometable', function (Blueprint $table) {
        $table->text('text')->change();
    });
}

doctrine/dbalこれを機能させるにはインストールする必要があります

composer require doctrine/dbal

Laravel 5.0 以降で動作します。Laravel 4.2 では動作しません。

于 2016-06-09T11:17:16.400 に答える
27

It's possible to do with a TABLE migration.

As mentioned in other posts, be sure to run composer require doctrine/dbal from your project root.

These are set up with:

php artisan make:migration alter_table_[yourtablenamehere]_change_[somecolumnname] --table=[yourtablenamehere]

from your project root.

From the Documentation:

https://laravel.com/docs/master/migrations#modifying-columns

class AlterTableSomething extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('table', function (Blueprint $table) {
            $table->text('column_name')->change();
        });
    }
}
于 2016-06-09T11:27:17.077 に答える