Skip to content

Instantly share code, notes, and snippets.

@jvadillo
Last active October 14, 2019 07:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jvadillo/a6bfa7ff11fabca5c6e89ddf58166221 to your computer and use it in GitHub Desktop.
Save jvadillo/a6bfa7ff11fabca5c6e89ddf58166221 to your computer and use it in GitHub Desktop.
Laravel: How to add new column to existing table using migration

Lanzar el comando:

php artisan make:migration add_columnA_to_tableX

Esto creará la migración add_columnA_to_tableX:

class AddcolumnAToTableX extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('tableX', function (Blueprint $table) {
            $table->string('nuevaColumna')->nullable();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('tableX', function (Blueprint $table) {
            $table->dropColumn(['nuevaColumna']);
        });
    }
}

Por último, ejecutar la migración:

php artisan migrate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment