Illuminate \ Database \ QueryException:SQLSTATE [42S02]:未找到基表或视图:1146表'avatr.apps'不存在(SQL:插入“ apps”

时间:2019-05-27 18:01:16

标签: laravel

我正在尝试用假数据测试数据库。我想运行php artisan db:seed,但出现错误。我不确定如何解决。

//App factory.php file
<?php

/* @var $factory \Illuminate\Database\Eloquent\Factory */


use Faker\Generator as Faker;

$factory->define(\App\app::class, function (Faker $faker) {
return [
    //

        'id' => $faker -> randomDigit,
        'UNIQUE_ACCOUNT_IDENTIFIER' => $faker -> randomDigit,
        'ACTIVITY_PERIOD' => $faker -> sentence(10),
        'SALES_CHANNEL' => $faker -> sentence(10),
        'MARKETPLACE' => $faker -> sentence(10),
        'TRANSACTION_TYPE' => $faker -> sentence(10),
        'TRANSACTION_EVENT_ID' =>  $faker-> randomDigit,
        'ACTIVITY-TRANSACTION-ID'=>  $faker-> randomDigit,
        'TAX_CALCULATION_DATE' =>  $faker-> date($format = 'Y-m-d', $max 
   = 'now'),
        'TRANSACTION_DEPART_DATE' =>  $faker-> date($format = 'Y-m-d', 
   $max = 'now'),
        'TRANSACTION_ARRIVAL_DATE' =>  $faker-> date($format = 'Y-m-d', 
   $max = 'now'),
        'TRANSACTION_COMPLETE_DATE' =>  $faker-> date($format = 'Y-m-d', 
  $max = 'now'),
        'SELLER_SKU' => $faker -> sentence(10),
        'ASIN' => $faker -> sentence(10),
        'ITEM_DESCRIPTION' => $faker -> sentence(10),
        'ITEM_MANUFACTURE_COUNTRY' =>  $faker-> country,
        'QTY' =>  $faker-> randomDigit,
        'ITEM_WEIGHT' => $faker-> randomDigit,
        'TOTAL_ACTIVITY_WEIGHT' => $faker-> randomDigit,
        'COST_PRICE_OF_ITEMS' => $faker-> randomDigit,
        'PRICE_OF_ITEMS_AMT_VAT_EXCL' => $faker-> randomDigit,
        'PROMO_PRICE_OF_ITEMS_AMT_VAT_EXCL' => $faker-> randomDigit,
        'TOTAL_PRICE_OF_ITEMS_AMT_VAT_EXCL' => $faker-> randomDigit,
        'SHIP_CHARGE_AMT_VAT_EXCL' => $faker-> randomDigit,
        'PROMO_SHIP_CHARGE_AMT_VAT_EXCL' => $faker-> randomDigit,
        'TOTAL_SHIP_CHARGE_AMT_VAT_EXCL' => $faker-> randomDigit,
        'GIFT_WRAP_AMT_VAT_EXCL' => $faker-> randomDigit,
        'PROMO_GIFT_WRAP_AMT_VAT_EXCL' => $faker-> randomDigit,
        'TOTAL_GIFT_WRAP_AMT_VAT_EXCL' => $faker-> randomDigit,
        'TOTAL_ACTIVITY_VALUE_AMT_VAT_EXCL' => $faker-> randomDigit,
        'PRICE_OF_ITEMS_VAT_RATE_PERCENT' => $faker-> randomDigit,
        'PRICE_OF_ITEMS_VAT_AMT' => $faker-> randomDigit,
        'PROMO_PRICE_OF_ITEMS_VAT_AMT' => $faker-> randomDigit,
        'TOTAL_PRICE_OF_ITEMS_VAT_AMT' => $faker-> randomDigit,
        'SHIP_CHARGE_VAT_RATE_PERCENT' => $faker-> randomDigit,
        'SHIP_CHARGE_VAT_AMT' => $faker-> randomDigit,
        'PROMO_SHIP_CHARGE_VAT_AMT' => $faker-> randomDigit,
        'TOTAL_SHIP_CHARGE_VAT_AMT' => $faker-> randomDigit,
        'GIFT_WRAP_VAT_RATE_PERCENT' => $faker-> randomDigit,
        'GIFT_WRAP_VAT_AMT' => $faker-> randomDigit,
        'PROMO_GIFT_WRAP_VAT_AMT' => $faker-> randomDigit,
        'TOTAL_GIFT_WRAP_VAT_AMT' => $faker-> randomDigit,
        'TOTAL_ACTIVITY_VALUE_VAT_AMT' => $faker-> randomDigit,
        'PRICE_OF_ITEMS_AMT_VAT_INCL' => $faker-> randomDigit,
        'PROMO_PRICE_OF_ITEMS_AMT_VAT_INCL' => $faker-> randomDigit,
        'TOTAL_PRICE_OF_ITEMS_AMT_VAT_INCL' => $faker-> randomDigit,
        'SHIP_CHARGE_AMT_VAT_INCL' => $faker-> randomDigit,
        'PROMO_SHIP_CHARGE_AMT_VAT_INCL' => $faker-> randomDigit,
        'TOTAL_SHIP_CHARGE_AMT_VAT_INCL' => $faker-> randomDigit,
        'GIFT_WRAP_AMT_VAT_INCL' => $faker-> randomDigit,
        'PROMO_GIFT_WRAP_AMT_VAT_INCL' => $faker-> randomDigit,
        'TOTAL_GIFT_WRAP_AMT_VAT_INCL' => $faker-> randomDigit,
        'TOTAL_ACTIVITY_VALUE_AMT_VAT_INCL' => $faker-> randomDigit,
        'TRANSACTION_CURRENCY_CODE' => $faker-> randomDigit,
        'COMODITY_CODE' => $faker-> randomDigit,
        'STATISTICAL_CODE_DEPART' => $faker-> randomDigit,
        'STATISTICAL_CODE_ARRIVAL' => $faker-> randomDigit,
        'COMMODITY_CODE_SUPPLEMENTARY_UNIT' => $faker-> randomDigit,
        'ITEM_QTY_SUPPLEMENTARY_UNIT' => $faker-> randomDigit,
        'TOTAL_ACTIVITY_SUPPLEMENTARY_UNIT' => $faker-> randomDigit,
        'PRODUCT_TAX_CODE' => $faker-> randomDigit,
        'DEPARTURE_CITY'  =>  $faker-> city,
        'DEPARTURE_COUNTRY' =>  $faker-> country,
        'DEPARTURE_POST_CODE'  =>  $faker-> postcode,
        'ARRIVAL_CITY' =>  $faker-> city,
        'ARRIVAL_COUNTRY' =>  $faker-> country,
        'ARRIVAL_POST_CODE'  =>  $faker-> postcode,
        'SALE_DEPART_COUNTRY' =>  $faker-> city,
        'SALE_ARRIVAL_COUNTRY' =>  $faker-> country,
        'TRANSPORTATION_MODE'   => $faker -> sentence(10),
        'DELIVERY_CONDITIONS' => $faker -> sentence(10),
        'SELLER_DEPART_VAT_NUMBER_COUNTRY' => $faker-> country,
        'SELLER_DEPART_COUNTRY_VAT_NUMBER' => $faker-> randomDigit,
        'SELLER_ARRIVAL_VAT_NUMBER_COUNTRY' => $faker-> country,
        'SELLER_ARRIVAL_COUNTRY_VAT_NUMBER' => $faker-> randomDigit,
        'TRANSACTION_SELLER_VAT_NUMBER_COUNTRY' => $faker-> country,
        'TRANSACTION_SELLER_VAT_NUMBER' => $faker-> randomDigit,
        'BUYER_VAT_NUMBER_COUNTRY' => $faker-> country,
        'BUYER_VAT_NUMBER' => $faker-> randomDigit,
        'VAT_CALCULATION_IMPUTATION_COUNTRY' => $faker-> country,
        'TAXABLE_JURISDICTIN' => $faker -> sentence(10),
        'TAXABLE_JURISTICTION_LEVEL' => $faker -> sentence(10),
        'VAT_INV_NUMBER' => $faker-> randomDigit,
        'VAT_INV_CONVERTED_AMT' => $faker-> randomDigit,
        'VAT_INV_CURRENCY_CODE' => $faker -> sentence(10),
        'VAT_INV_EXCHANGE_RATE' => $faker -> sentence(10),
        'VAT_INV_EXCHANGE_RATE_DATE' =>  $faker-> date($format = 'Y-m-d', $max = 'now'),
        'EXPORT_OUTSIDE_EU' =>  $faker -> sentence(10),
        'INVOICE_URL' => $faker -> url,
        'BUYER_NAME' => $faker -> sentence(10),
        'ARRIVAL_ADRESS' => $faker -> address
      ];
     });

   // App seeder file

<?php

use Illuminate\Database\Seeder;

class AppSeeder extends Seeder
{
/**
 * Run the database seeds.
 *
 * @return void
 */
public function run()
{
    //radi za app factory, ovo 10 znači 10 puta
   factory(App\app::class, 10) -> create();
}
}

// app controler

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class AppController extends Controller
{
//
public function index () {
    return view('app.index');
}
}


Illuminate\Database\QueryException  : SQLSTATE[42S02]: Base table or view 
not found: 1146 Table 'avatr.apps' doesn't exist (SQL: insert into `apps`


at C:\laragon\www\pullus- 
app\vendor\laravel\framework\src\Illuminate\Database\Connection.php:664
660|         // If an exception occurs when attempting to run a query, 
we'll format the error
661|         // message to include the bindings with SQL, which will make 
this exception a
662|         // lot more helpful to the developer instead of just the 
database's errors.
663|         catch (Exception $e) {
664|             throw new QueryException(
665|                 $query, $this->prepareBindings($bindings), $e
666|             );
667|         }
668|


 PDOException::("SQLSTATE[42S02]: Base table or view not found: 1146 
 Table 'avatr.apps' doesn't exist")
  C:\laragon\www\pullus- 
 app\vendor\laravel\framework\src\Illuminate\Database\Connection.php:452

2   PDO::prepare("insert into `apps`

1 个答案:

答案 0 :(得分:0)

如果要使用工厂,首先需要为要播种的每个表定义一个模型:https://laravel.com/docs/5.8/eloquent#defining-models

接下来,您为每种模型定义一个工厂:https://laravel.com/docs/5.8/database-testing#writing-factories

最后,您需要制作一个将使用工厂的播种机:https://laravel.com/docs/5.8/seeding