i am trying to run:
php artisan db:seed
and i get this error:
Illuminate\Database\QueryException
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'homestead.Users' doesn't exist (SQL: truncate table `Users`)
this is the code from databaseseeder.php:
as you can see , i truncate the users table which is created in user.php MODEL, database seeder code here:
public function run()
{
// \App\Models\User::factory(10)->create();
DB::statement('SET FOREIGN_KEY_CHECKS=0');
User::truncate();
Category::truncate();
Product::truncate();
Transaction::truncate();
DB::table('category_product')->truncate();
$cantidadUsuarios = 200;
$cantidadCategories = 30;
$cantidadProductos = 1000;
$cantidadTransacciones = 1000;
factory(User::class, $cantidadUsuarios)->create();
factory(Category::class, $cantidadCategories)->create();
factory(Category::class, $cantidadTransacciones)->create()->each(
function ($producto) {
$categorias = Category::all()->random(mt_rand(1, 5))->pluck('id');
$producto->categories()->attach($categories->first());
}
);
factory(Transaction::class, $cantidadTransacciones)->create();
}
}
here is the user model class:
as you can see i am defining the table name in:
public $table = "Users";
the solution came from here: Base table or view not found: 1146 Table Laravel 5
but still does not works, i also... ran "php artisan migrate"
, to make sure i am not leaving something out,
then i ran php artisan db:seed, however did not worked out,
User.php model class:
<?php
namespace App\Models;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
class User extends Authenticatable
{
public $table = "Users";
use HasFactory, Notifiable;
const USUARIO_VERIFICADO = '1';
const USUARIO_NO_VERIFICADO = '0';
const USUARIO_ADMINISTRADOR = 'TRUE';
const USUARIO_REGULAR = 'FALSE';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name',
'email',
'password',
'verified',
'verification_token',
'admin',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password',
'remember_token',
'verification_token',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
public function esVerificado()
{
return $this->verified == User::USUARIO_VERIFICADO;
}
public function esAdministrador()
{
return $this->verified == User::USUARIO_ADMINISTRADOR;
}
public static function generarVerificationToken()
{
return str_random(40);
}
}
and also here is the USERS CREATE MIGRATION CLASS:
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use App\Models\User;
class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->string('verified')->default(User::USUARIO_NO_VERIFICADO);
$table->string('verification_token')->nullable();
$table->string('admin')->default(User::USUARIO_REGULAR);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('users');
}
}
i do not know what i am doing wrong, so i come here seeking for some light from StackOverflow community to help me, since i do not know what is wrong and i am just starting with laravel,
i submmited all the useful information in order to determine what is the problem
if you need something else please feel free to request it, thank you thank you