Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Mauro19's avatar

Base table of view not found: 1146 Table doesn't exist

I'm using Nova and for a nova resource:"Client" that I needed I created a new migration with the following command:

$ php artisan make:migration create_clients_table --create=clients

added the necessary fields and created the table "clients" :

$ php artisan migrate

then created the corresponding Model "Client":

$ php artisan make:model Client

Check that everything went well by adding some clients to the table using tinker:

>>> $client = new App\Client()
>>> $client->name = "Lucas"
>>> $client->company = "GMC"
>>> $client->mail = "[email protected]"
>>> $client->save()

Finally crated the resource "Client" with:

$ php artisan nova:resource Client

So far so good. Everything quite simple.

In Nova, the Client resource is available and in the listing I see all the test clients added in tinker, the view page and delete work as well but, after adding the required fields, when I try to click on Create Client or update an existing client (i.e.: Lucas) I get the following error:

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'database.client' doesn't exist (SQL: select count(*) as aggregate from 'client' where 'email'[email protected])

I don't understand why is trying to query the client table in singular

Any ideas will be greatly appreciated. Thanks in advance

0 likes
5 replies
mvdnbrk's avatar

Can you paste in the code of the fields() method of the Client resource?

Anything else changed in \App\Nova\Client ?

Mauro19's avatar

@mvdnbrk sure. I used Panels to group the different fields:

public function fields(Request $request)
    {
        return [
            ID::make()->sortable(),

            new Panel('Client Details', $this->clientDetailFields()),
            new Panel('Address Information', $this->addressFields()),
            new Panel('Billing Address', $this->billingFields()),
        ];
    }

    protected function clientDetailFields ()
    {
        return [
            Text::make('Name')->rules('required'),
            Text::make('Company')->rules('required'),
            PhoneNumber::make('Phone Number')->rules('required'),
            PhoneNumber::make('Phone Number 2')->onlyOnDetail(),
            Text::make('Email')->rules('required', 'email', 'unique:client'),
            Password::make('Password')->rules('required', 'min:3')->onlyOnForms(),
            Text::make('Website')->onlyOnDetail()->showOnUpdating(),
            Select::make('Gender')->options([
                'male' => 'Male',
                'female' => 'Female'
            ])->onlyOnDetail()->showOnUpdating(),
            Date::make('Birthday')->onlyOnDetail()->showOnUpdating(),
            Text::make('Nationality')->onlyOnDetail()->showOnUpdating(),
            Boolean::make('Active', 'status')->hideWhenCreating()
        ];
    }

    protected function addressFields ()
    {
        return [
            Text::make('Address Line 1')->hideFromIndex(),
            Text::make('Address Line 2')->hideFromIndex(),
            Text::make('Postal Code')->hideFromIndex(),
            Text::make('City')->hideFromIndex(),
            Text::make('Country')->hideFromIndex(),
            Text::make('Region')->hideFromIndex()
        ];
    }

    protected function billingFields ()
    {
        return [
            Text::make('Address Line 1', 'billing_address_line1')->onlyOnDetail()->showOnUpdating(),
            Text::make('Address Line 2', 'billing_address_line2')->onlyOnDetail()->showOnUpdating(),
            Text::make('Postal Code', 'billing_postal_code')->onlyOnDetail()->showOnUpdating(),
            Text::make('City', 'billing_city')->onlyOnDetail()->showOnUpdating(),
            Text::make('Country', 'billing_country')->onlyOnDetail()->showOnUpdating(),
            Text::make('Region', 'billing_region')->onlyOnDetail()->showOnUpdating()
        ];
    }
Mauro19's avatar

Now that I see I supposed it has something to do with the rule that I applied to the email field? I thought that the parameter to pass to unique was the model and not the table

mvdnbrk's avatar

The problem is here I guess:

Text::make('Email')->rules('required', 'email', 'unique:client'),

You have a validation rule to check if the email is unique. It will check against the client table.

So change that to clients

Please or to participate in this conversation.