Unable to add BREAD to table
admiralmedia opened this issue · 5 comments
Laravel version
9.52.16
PHP version
8.3.3-1+020240216.17+debian101.gbp87e37b
Voyager version
1.7
Database
MariaDB version 10.3.39
Description
I'm trying to create a simple project but got stuck on the first step as follows.
- Installed a brand new Laravel
- Installed a brand new Voyager
- Created a table named Test with 3 columns: id, Test1, Test2. Table created as project.Test
- Add BREAD with default settings and save.
- Try to browse newly created BREAD but all I've got is 500 Error as bellow:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'project.tests' doesn't exist (SQL: select
Test.* from
testsorder by
created_atdesc) {"userId":1,"exception":"[object] (Illuminate\\Database\\QueryException(code: 42S02): SQLSTATE[42S02]: Base table or view not found: 1146 Table 'project.tests' doesn't exist (SQL: select
Test.* from
testsorder by
created_atdesc) at /home/project/public_html/vendor/laravel/framework/src/Illuminate/Database/Connection.php:760)
As I undestand the table name is created as singular but the browse BREAD is looking for the plural name of the table!
Steps to reproduce
I'm trying to create a simple project but got stuck on the first step as follows.
- Installed a brand new Laravel
- Installed a brand new Voyager
- Created a table named Test with 3 columns: id, Test1, Test2. Table created as project.Test
- Add BREAD with default settings and save.
- Try to browse newly created BREAD but all I've got is 500 Error as bellow:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'project.tests' doesn't exist (SQL: select
Test.* from
testsorder by
created_atdesc) {"userId":1,"exception":"[object] (Illuminate\\Database\\QueryException(code: 42S02): SQLSTATE[42S02]: Base table or view not found: 1146 Table 'project.tests' doesn't exist (SQL: select
Test.* from
testsorder by
created_atdesc) at /home/project/public_html/vendor/laravel/framework/src/Illuminate/Database/Connection.php:760)
Expected behavior
Browse the BREAD
Screenshots
Additional context
No response
Change the database table to "tests". You want to make your table names plural in most cases.
Change the database table to "tests". You want to make your table names plural in most cases.
I've created(also renamed) several times the table with name Tests(plural form) but all I got was the same error when browsing Bread:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'project.tests' doesn't exist (SQL: select
Tests.* from
testsorder by
created_atdesc) {"userId":1,"exception":"[object] (Illuminate\\Database\\QueryException(code: 42S02): SQLSTATE[42S02]: Base table or view not found: 1146 Table 'project.tests' doesn't exist (SQL: select
Tests.* from
testsorder by
created_atdesc) at /home/project/public_html/vendor/laravel/framework/src/Illuminate/Database/Connection.php:760)
I've figured out what the issue was as follows:
- The table needs to be in plural form like tests
- The table need to contain the fields: created_at, updated_at, modified_at
Hello,
Tables needs names in all small letters and plural.
Not Test, not Tests, not test
But should be tests
Kind regards
John
manually create model for Test (model name) ** better to reallocate model directly inside app folder App
i.e: Modal Name = 'App\Models*Test*'
php artisan make:model Test
add below codes on Test Model
`
class Test extends Model
{
protected $primaryKey='id';
use HasFactory;
public $table= 'Test';
public $timestamps=false;
`