F
Filament10mo ago
RMH

SQLSTATE[HY000]: General error: 1364 Field 'guardian_id' doesn't have a default value

I have a StudentResource and in form I am doing this:
Forms\Components\Select::make('guardian_id')
->relationship('guardian', 'family_name')
->label('Family')
->searchable()
->preload()
->required(),
Forms\Components\Select::make('guardian_id')
->relationship('guardian', 'family_name')
->label('Family')
->searchable()
->preload()
->required(),
But while creating a new student I am getting this error SQLSTATE[HY000]: General error: 1364 Field 'guardian_id' doesn't have a default value
3 Replies
waleedGRT
waleedGRT10mo ago
Can you show a migration file?
cheesegrits
cheesegrits10mo ago
Make sure it's $fillable in the model.
RMH
RMH10mo ago
Sure the student migration file is:
Schema::create('students', function (Blueprint $table) {
$table->id();
$table->foreignId('guardian_id')
->constrained()
->restrictOnDelete();
$table->string('reg_no')->unique();
$table->string('first_name');
$table->string('last_name')->nullable();
// Other columns
});
Schema::create('students', function (Blueprint $table) {
$table->id();
$table->foreignId('guardian_id')
->constrained()
->restrictOnDelete();
$table->string('reg_no')->unique();
$table->string('first_name');
$table->string('last_name')->nullable();
// Other columns
});
yeah... missed that... thanks