Skip to content

Can't create a not nullable generated column in mysql #31398

Closed
@DrCake

Description

@DrCake
  • Laravel Version: 6.14.0
  • PHP Version: 7.4.0
  • Database Driver & Version: MySQL 8.0.19

Description:

When creating a generated column in my migration, the nullable() modifier method has no effect on the column that is created. It looks like this was disabled to fix an issue back in 5.3 but hasn't been re-enabled now that MySQL supports it.

Steps To Reproduce:

The Migration

class CreateAddressesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('addresses', function (Blueprint $table) {
            $table->bigIncrements('id');

            $table->string('name');

            $table->decimal('latitude');
            $table->decimal('longitude');

            $table->point('location', 4326)->nullable(false)->storedAs('Point(`latitude`, `longitude`)');

            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('addresses');
    }
}

Running this migration, if you inspect the database you will see that the location column is nullable. So if you try and add a spatial index on the location column, you will get an error that you can't create the index on a column that is allowed to be null

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions