0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Laravel】migrationでカラムの型が変更できない場合の対処法!

Posted at

泉(@izumin_0401)です。

今回は、Laravelのmigrationでカラムの型が変更できない場合の対処法を解説しやす!

ブログ記事はこちら

【Laravel】migrationでカラムの型が変更できない場合の対処法

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    public function up()
    {
        DB::connection()->getPdo()->exec('ALTER TABLE your_table ALTER COLUMN your_column TYPE VARCHAR(10);');
    }

    public function down()
    {
        DB::connection()->getPdo()->exec('ALTER TABLE your_table ALTER COLUMN your_column TYPE CHAR(10);');
    }
};

上記のように、直接SQLを実行すれば解決します。

まとめ

結構ハマった。。

ではまた!

最後に

暇つぶしにTwitterブログもやってるので見てね。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?