nova-sortable icon indicating copy to clipboard operation
nova-sortable copied to clipboard

General error: 1364 Field 'sort_order' doesn't have a default value

Open SebastianBotez opened this issue 1 year ago • 1 comments

I get an error when creating a new entry using Nova 3.29.

General error: 1364 Field 'sort_order' doesn't have a default value

Model:

public $sortable = [
    'order_column_name' => 'sort_order',
    'sort_when_creating' => true,
];

Nova Resource: use HasSortableRows;

Any solutions for this?

SebastianBotez avatar Feb 16 '24 08:02 SebastianBotez

You can change your migration by adding default value

$table->integer('sort_order')->default(0)

Or make a new migration to refactor existing one by

php artisan make:migration set_default_sort_order_into_YOUR-TABLE-NAME_table

And insert this into migration

public function up(): void
    {
        Schema::table(YOUR-TABLE-NAME, function (Blueprint $table) {
            $table->integer('sort_order')
                ->default(0)->change();
        });
    }
    
    public function down(): void
    {
        Schema::table(YOUR-TABLE-NAME, function (Blueprint $table) {
            $table->integer('sort_order')->change();
        });
    }

Just don't forget to change YOUR-TABLE-NAME:)

TriStarRiT avatar Mar 26 '24 11:03 TriStarRiT