F
Filament4w ago
Dale

Resource > Page > Create fails

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?
24 Replies
Dale
DaleOP4w ago
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))
Dale
DaleOP4w ago
I have these other resources listed on the navigation pane working correctly and I have compared models, resources, pages etc.
No description
Dale
DaleOP4w ago
The donations Listing View is from the manually inserted DB rows and uses the same Model.
Dale
DaleOP4w ago
My model is very simple
No description
Matthew
Matthew4w ago
HAve you tried running the SQL Statement directly on the database. Perhaps you have an errant trigger or something setup?
Matthew
Matthew4w ago
Can you share your migration file? I see that your file name is donation.php, but it should be Donation.php That is also why the class name is highlighted
Dale
DaleOP4w ago
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.
awcodes
awcodes4w ago
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.
Dale
DaleOP4w ago
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); } }
Dale
DaleOP4w ago
Form I'm trying to submit:
No description
Dale
DaleOP4w ago
Full error message
No description
Dale
DaleOP4w ago
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. I used Blueprint package to generate my models and migration files.
Matthew
Matthew4w ago
Need to see the migration file.
Dale
DaleOP4w ago
I added it just before the screenshot of the Create Donation form.
Matthew
Matthew4w ago
That's the model ?
Dale
DaleOP4w ago
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'); } };
Dale
DaleOP4w ago
This is from PhpStorm's dictionary query.
No description
Dale
DaleOP4w ago
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.
Matthew
Matthew4w ago
Schema::create('donations', function (Blueprint $table) {
$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();
});
Schema::create('donations', function (Blueprint $table) {
$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
Dale
DaleOP4w ago
Matthew, you are a beautiful person. Thank you for your assistance. This was in fact the issue!!
awcodes
awcodes4w ago
Thank you @Matthew
Matthew
Matthew4w ago
The clash of the 2 Matthew's 🤣
awcodes
awcodes4w ago
lol. Sorry. This is my brother Doug, and this is my other brother Doug.
Dale
DaleOP4w ago
🙂

Did you find this page helpful?