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

Unable to add BREAD to table #5843

Open
admiralmedia opened this issue Feb 21, 2024 · 5 comments
Open

Unable to add BREAD to table #5843

admiralmedia opened this issue Feb 21, 2024 · 5 comments

Comments

@admiralmedia
Copy link

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.

  1. Installed a brand new Laravel
  2. Installed a brand new Voyager
  3. Created a table named Test with 3 columns: id, Test1, Test2. Table created as project.Test
  4. Add BREAD with default settings and save.
  5. 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 bycreated_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: selectTest.* from testsorder bycreated_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.

  1. Installed a brand new Laravel
  2. Installed a brand new Voyager
  3. Created a table named Test with 3 columns: id, Test1, Test2. Table created as project.Test
  4. Add BREAD with default settings and save.
  5. 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 bycreated_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: selectTest.* from testsorder bycreated_atdesc) at /home/project/public_html/vendor/laravel/framework/src/Illuminate/Database/Connection.php:760)

Expected behavior

Browse the BREAD

Screenshots

bread1

Additional context

No response

@Emerica
Copy link
Contributor

Emerica commented Feb 21, 2024

Change the database table to "tests". You want to make your table names plural in most cases.

@admiralmedia
Copy link
Author

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 bycreated_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: selectTests.* from testsorder bycreated_atdesc) at /home/project/public_html/vendor/laravel/framework/src/Illuminate/Database/Connection.php:760)

@admiralmedia
Copy link
Author

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

@Jhamende
Copy link

Jhamende commented Mar 14, 2024

Hello,

Tables needs names in all small letters and plural.

Not Test, not Tests, not test
But should be tests

Kind regards
John

@rawtion
Copy link

rawtion commented Mar 23, 2024

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;

`

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

No branches or pull requests

4 participants