#Resource > Page > Create fails

30 messages · Page 1 of 1 (latest)

hushed ridge
#

I have a resource created with the make:filament-resourse Donation --generate and all of actions work except for create.

I have also created a dozen other Resources using this pattern and they all work.

When I summit the create I'm receiving an SQL table doest exist. The table does exist and after I manually insert a record in the DB table the list and edit pages work.

I have compared the model to others, this Resource to others and found no differences other than the model/table name. I have checked to see if I have a pluralization issue and none found.

The sql error reads

SQLSTATE[HY000]: General error: 1 no such table:main. (Connection: sqlite, SQL: insert into "donations" and then the columns and correct data.

I have tried the various troubleshooting steps this discord channel mentions. I have also regenerated the resource and add, edit delete pages.

Any ideas?

hushed ridge
#

Here is the full text and I'm not sure if this is a Filament, Livewire or Laravel issue.

#

Illuminate\Database\QueryException
SQLSTATE[HY000]: General error: 1 no such table: main. (Connection: sqlite, SQL: insert into "donations" ("donor_id", "date", "amount", "recurring", "notes", "donationtype_id", "updated_at", "created_at") values (1, 2025-04-07 10:49:14, 1, 0, ?, 1, 2025-04-07 17:49:25, 2025-04-07 17:49:25))

#

I have these other resources listed on the navigation pane working correctly and I have compared models, resources, pages etc.

#

The donations Listing View is from the manually inserted DB rows and uses the same Model.

#

My model is very simple

shy dirge
#

HAve you tried running the SQL Statement directly on the database.

Perhaps you have an errant trigger or something setup?

ruby notch
ruby notch
#

That is also why the class name is highlighted

hushed ridge
#

I just discovered that even from Tinker I can't insert a new record but can for other tables. I assume that this means I have an issue somewhere between the model and the table in the DB. When I tried to DB::table("Donations")->insert([....... it failed in the same way.

slender egret
#

Please share your migration file. It’s sounds like the issue is there. But Matthew is also correct that the model file should be named Donation.php with a capital ‘D’ to conform with psr standards.

hushed ridge
#

I have now corrected the case of the Model names (thank you both).

#

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;

class Donation extends Model
{
use HasFactory, SoftDeletes;

protected $casts = [
    'id' => 'integer',
    'donor_id' => 'integer',
    'date' => 'datetime',
    'amount' => 'decimal:2',
    'recurring' => 'boolean',
    'donationtype_id' => 'integer',
];

public function donor(): BelongsTo
{
    return $this->belongsTo(Donor::class);
}

public function donationtype(): BelongsTo
{
    return $this->belongsTo(Donationtype::class);
}

}

#

Form I'm trying to submit:

#

Full error message

#

In my example both the donor_id and donationtype_id point to valid records in the associated tables. I have written plenty of Laravel code over the past 4 years but for the life of me I cant see what I missed.

hushed ridge
#

I used Blueprint package to generate my models and migration files.

shy dirge
#

Need to see the migration file.

hushed ridge
#

I added it just before the screenshot of the Create Donation form.

shy dirge
#

That's the model ?

hushed ridge
#

Sorry I'm an idiot, I opened the migration but copied the model.

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::disableForeignKeyConstraints();

    Schema::create('donations', function (Blueprint $table) {
        $table->id();
        $table->foreignId('donor_id')->constrained();
        $table->dateTime('date');
        $table->decimal('amount', 8, 2);
        $table->boolean('recurring')->default(false);
        $table->text('notes')->nullable();
        $table->foreignId('donationtype_id')->constrained('');
        $table->timestamps();
        $table->softDeletes();
    });

    Schema::enableForeignKeyConstraints();
}

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

};

#

This is from PhpStorm's dictionary query.

#

The migration file I listed was generated by Blueprint but the donationtype_id constrained seems to be formatted with a ('') whereas the donor_id is not.

shy dirge
#
            $table->id();
            $table->foreignId('donor_id')->constrained(table: 'donors');
            $table->dateTime('date');
            $table->decimal('amount', 8, 2);
            $table->boolean('recurring')->default(false);
            $table->text('notes')->nullable();
            $table->foreignId('donationtype_id')->constrained(table: 'donationtypes');
            $table->timestamps();
            $table->softDeletes();
        });```

Try that
hushed ridge
#

Matthew, you are a beautiful person. Thank you for your assistance. This was in fact the issue!!

slender egret
#

Thank you @shy dirge

ruby notch
#

The clash of the 2 Matthew's 🤣

slender egret
#

lol. Sorry.

#

This is my brother Doug, and this is my other brother Doug.