gpt4 book ai didi

php - Laravel :"php artisan db:seed"不工作

转载 作者:可可西里 更新时间:2023-11-01 01:00:11 25 4
gpt4 key购买 nike

我尝试在数据库中运行“ServiceTableSeeder”表时收到错误消息。

我尝试运行“php artisan db:seed

消息:

[symfony\component|Debug\Exception\FetalErrorException]
cannot redeclare DatabaseSeeder::run()

数据库播种器.php

<?php

use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;

class DatabaseSeeder extends Seeder {

/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Eloquent::unguard();
$this->call('ServiceTableSeeder');

}

}

ServiceTableSeeder.php

<?php

class ServiceTableSeeder extends Seeder {

public function run()
{
Service::create(
array(
'title' => 'Web development',
'description' => 'PHP, MySQL, Javascript and more.'
)
);

Service::create(
array(
'title' => 'SEO',
'description' => 'Get on first page of search engines with our help.'
)
);

}
}

如何解决这个问题。我是 laravel 的新手,请指导我。

最佳答案

对于那些面临同样问题的人,请确认 .env 文件中的 APP_ENV 变量,因为如果我们设置了 Laravel 不允许我们运行 db:seed

'APP_ENV = Production'

为了数据库记录。

因此,确保将 APP_ENV 的值设置为“staging”或“local”,然后运行 ​​php artisan db:seed

关于php - Laravel :"php artisan db:seed"不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29727510/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com