Php artisanmigrate:fresh --seed не может заполнить таблицу в MySQLPhp

Кемеровские программисты php общаются здесь
Ответить
Anonymous
 Php artisanmigrate:fresh --seed не может заполнить таблицу в MySQL

Сообщение Anonymous »

Я только начал изучать PHP и Laravel 7, не имея предварительного опыта. Я думаю, что у нас с Artisan возникли проблемы с доверием, и я не знаю, почему. :)
Я дошел до этапа раздачи и столкнулся с ошибкой, для простого решения которой мне нужен ваш опыт. Ниже приведены предыдущие шаги, которые я сделал до того, как столкнулся с этой проблемой.

Я создаю контроллер и модель продукта

Код: Выделить всё

php artisan make:model Product -m -c -resource
База данных

Код: Выделить всё

class CreateProductsTable extends Migration
{
public function up()
{
Schema::create('products', function (Blueprint $table) {
$table->id();
$table->string('name', 100);
$table->string('image')->nullable();
$table->string('type');
$table->decimal('price', 2);
$table->text('description')->nullable();
$table->timestamps();
});
}

public function down()
{
Schema::dropIfExists('products');
}
}
Модель

Код: Выделить всё

class Product extends Model
{
protected $table = 'product';
protected $fillable = ['name', 'image', 'type', 'price', 'description'];
}
Контроллер

Код: Выделить всё

class ProductController extends Controller
{

public function __construct()
{
$this->middleware('auth');
}

public function index()
{
$product = DB::table('products')->get();
}
}
AppServiceProvider

Код: Выделить всё

class AppServiceProvider extends ServiceProvider
{
public function register()
{
Schema::defaultStringLength(191);
}
}
После этого я создал ProductTableSeeder


php artisan make:seeder ProductTableSeeder

Код: Выделить всё

class ProductTableSeeder extends Seeder
{
public function run()
{
Product::insert([
'name' => 'iphone',
'type' => 'smart phone',
'price' => 1000.98,
'description' => 'Cillum sint dolore sint labori',
]);

Product::insert([
'name' => 'Galaxy',
'type' => 'tablets',
'price' => 2000.50,
'description' => 'Cillum sint dolore sint labori',
]);

Product::insert([
'name' => 'Sony',
'type' => 'TV',
'price' => 3000,
'description' => 'Cillum sint dolore sint labori',
]);
}
}
затем называется сеялкой

Код: Выделить всё

class DatabaseSeeder extends Seeder
{
public function run()
{
// $this->call(UserSeeder::class);
$this->call(ProductTableSeeder::class);
}
}
Затем композитор дамп-автозагрузка

Наконец, после ввода команды заполнения

Код: Выделить всё

php artisan migrate:fresh --seed
Я постоянно получаю следующую ошибку.

Код: Выделить всё

Dropped all tables successfully.
Migration table created successfully.
Migrating: 2014_10_12_000000_create_users_table
Migrated:  2014_10_12_000000_create_users_table (0.51 seconds)
Migrating: 2019_08_19_000000_create_failed_jobs_table
Migrated:  2019_08_19_000000_create_failed_jobs_table (0.12 seconds)
Migrating: 2020_04_13_063011_create_products_table
Migrated:  2020_04_13_063011_create_products_table (0.18 seconds)
Seeding: ProductTableSeeder

Illuminate\Database\QueryException

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'e-commerce.product' doesn't exist (SQL: insert into `product`
(, тип, цена, описание) значения (iphone, смартфон,
1000,98, Cillum sint dolore sint Labori))

Код: Выделить всё

  at C:\wamp64\www\E-Commerce\vendor\laravel\framework\src\Illuminate\Database\Connection.php:671
667|         // If an exception occurs when attempting to run a query, we'll format the error
668|         // message to include the bindings with SQL, which will make this exception a
669|         // lot more helpful to the developer instead of just the database's errors.
670|         catch (Exception $e) {
>  671|             throw new QueryException(
672|                 $query, $this->prepareBindings($bindings), $e
673|             );
674|         }
675|

• A table was not found: You might have forgotten to run your migrations. You can run your migrations using `php artisan migrate`.
https://laravel.com/docs/master/migrations#running-migrations

1   C:\wamp64\www\E-Commerce\vendor\laravel\framework\src\Illuminate\Database\Connection.php:458
PDOException::("SQLSTATE[42S02]: Base table or view not found: 1146 Table 'e-commerce.product' doesn't exist")

2   C:\wamp64\www\E-Commerce\vendor\laravel\framework\src\Illuminate\Database\Connection.php:458
PDO::prepare("insert into `product` (`name`, `type`, `price`, `description`) values (?, ?, ?, ?)")


Подробнее здесь: https://stackoverflow.com/questions/617 ... into-mysql
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Php»