2
votes

Error:

Illuminate \ Database \ QueryException (42S02) SQLSTATE[42S02]: Base table or view not found: 1146 Table 'mmictltd.admins' doesn't exist (SQL: select * from admins where email = [email protected] limit 1)

My create_admin_table.php

<?php

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

class CreateAdminTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('admin', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->string('email')->unique();
            $table->string('password');
            $table->rememberToken();
            $table->timestamps();
        });
    }

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

Laravel error illustration

3
I wonder why it says select * from admins yet my table is adminX Roney Cyberking

3 Answers

7
votes

Your table's in migration is called 'admin' but in query you are looking for 'admins'.

You can specific table name in your model by $table:

/**
 * The table associated with the model.
 *
 * @var string
 */
protected $table = 'admin';

Laravel convention is that table names should be plural in this case: https://laravel.com/docs/5.6/eloquent

So I recommend you to change your migration from 'admin' to 'admins'.

0
votes

By default laravel uses the "snake case", plural name of the class will be used as the table name unless another name is explicitly specified. So inside your Admin eloquent model you must define the $table property for your case as

protected $table = 'admin';

Check the eloquent model class convetion here https://laravel.com/docs/5.6/eloquent#eloquent-model-conventions

0
votes

I ran into a similar difficulty trying to deploy my application on App engine. I will share with you how I fixed it.

  • remove routes from api.php (I didn't need these for my application)
  • enable cloud SQL api enable
  • Follow this tutorial tutorial follow next two steps before deploying
  • make the following changes to the composer.json file. The tutorial is incorrect.
"post-install-cmd": [
            "Illuminate\\Foundation\\ComposerScripts::postInstall",
            "php artisan optimize",
            "chmod -R 755 bootstrap\/cache"
        ]
  • Configure your app.yaml file like so:
  • runtime: php
    env: flex
    
    runtime_config:
      document_root: public
    
    env_variables:
      # Put production environment variables here.
      APP_ENV: production
      APP_LOG: errorlog
      APP_KEY: APP_KEY (DO NOT USE QUOTES)
      CACHE_DRIVER: database
      SESSION_DRIVER: database
      ## Set these environment variables according to your CloudSQL configuration.
      DB_HOST: localhost
      DB_PORT: 3306
      DB_CONNECTION: mysql
      DB_DATABASE: DATABASE_NAME (DO NOT USE QUOTES)
      DB_USERNAME: USERNAME (DO NOT USE QUOTES)
      DB_PASSWORD: PASSWORD (DO NOT USE QUOTES)
      DB_SOCKET: /cloudsql/YOUR_INSTANCE_CONNECTION_NAME (DO NOT USE QUOTES)
    
      QUEUE_DRIVER: database
    
    beta_settings:
        # for Cloud SQL, set this value to the Cloud SQL connection name,
        # e.g. "project:region:cloudsql-instance"
        cloud_sql_instances: "YOUR_INSTANCE_CONNECTION_NAME"