nova-sortable
nova-sortable copied to clipboard
General error: 1364 Field 'sort_order' doesn't have a default value
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?
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:)