【问题标题】:Base table or view not found for faker Database in laravellaravel中的faker数据库找不到基表或视图
【发布时间】:2020-05-23 04:12:55
【问题描述】:

我在 Laravel 中有错误

当我们 $ php artisan db:seed 在 git
错误是:

Illuminate\Database\QueryException:SQLSTATE[42S02]:未找到基表或视图:1146 表 'noor_app.noors' 没有 t存在(SQL:插入noorstitledescriptioncompletedupdated_atcreated_at)值(Voluptates fac ilis velit repellat., Iure facere dolore ea earum。 Temporibus nesciunt minima eos., 0, 2020-02-07 02:11:12, 2020-02-07 02: 11:12))

mysql 中的信息 我的数据库名为:noor_app 我的桌子叫: failed_jobs-migrations-noor-password_resets-users


工厂文件是:
noorFactory.php 用户工厂.php
这是 noorFactory.php

<?php

use Illuminate\Database\Seeder;
class noorSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        factory(App\noor::class , 10)->create();

    }
}


迁移文件 这是 2020_02_06_000033_create_noor_table.php

<?php

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

class CreateNoorTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('noor', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('title');
            $table->text('description');
            $table->boolean('completed');
            $table->timestamps();
        });
    }

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


速度文件 这是 noorSpeeder.php

<?php

use Illuminate\Database\Seeder;
class noorSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        factory(App\noor::class , 10)->create();

    }
}


速度文件 这是 DatabaseSpeeder.php

<?php

use Illuminate\Database\Seeder;

class DatabaseSeeder extends Seeder
{
    /**
     * Seed the application's database.
     *
     * @return void
     */
    public function run()
    {
       $this->call(noorSeeder::class);
    }
}


提供者文件 这是 AppServiceProvider.php

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;


class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        //
    }
}


提供者文件 这是 noor.php


namespace App;

use Illuminate\Database\Eloquent\Model;

class noor extends Model
{
    //
}

如何修复此错误以制作虚假数据库
谢谢

【问题讨论】:

  • 还显示‘noor’模型里面有什么

标签: php laravel web


【解决方案1】:

Laravel 约定

按照约定,将使用类的“snake case”,复数名 作为表名,除非明确指定另一个名称。所以,在 在这种情况下,Eloquent 将假设 noor 模型将记录存储在 诺尔斯表。

但是,如果您想使用当前表名“noor”,您可以通过在模型上定义表属性来指定自定义表:

protected $table = 'noor';

【讨论】:

    【解决方案2】:

    将mysql中的表重命名为“noors”,并根据新表名适当调整模型和迁移。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-08
      • 1970-01-01
      • 2016-09-23
      • 2016-01-25
      • 1970-01-01
      • 1970-01-01
      • 2021-09-24
      相关资源
      最近更新 更多