Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
SebastianBotez opened this issue Feb 16, 2024 · 1 comment

Comments

@SebastianBotez
Copy link

SebastianBotez commented Feb 16, 2024

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?

@TriStarRiT
Copy link

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:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants