Laravel4 数据库播种器错误 - 调用未定义的方法 SeedDummyOrders::setContainer()
Posted
技术标签:
【中文标题】Laravel4 数据库播种器错误 - 调用未定义的方法 SeedDummyOrders::setContainer()【英文标题】:Laravel4 Database Seeder error - Call to undefined method SeedDummyOrders::setContainer() 【发布时间】:2015-04-28 20:35:15 【问题描述】:我的数据库中有两个表:
order_header order_details我需要一些虚拟数据,所以我创建了以下 SeedDummyOrders 类:
<?php
class SeedDummyOrders
public function run()
DB::table('order_details')->delete();
DB::table('order_header')->delete();
$inventory_ids = range(1, 10);
for ($i = 1; $i <= 5; $i++)
$order = new \OrderHeader;
$order->owner_id = 1;
$order->order_number = '100' . $i;
$order->delivery_type = 'Standard';
$order->order_status = 'Received';
$order->address_line1 = $i . ', Some Street';
$order->city = 'London';
$order->postcode = 'ABC D' . $i;
$order->country_code = 'GB';
$order->country_name = 'Great Britain';
$order->contact_name = 'Mr Person ' . $i;
$order->contact_email = 'contact' . $i . '@mail.com';
$order->save();
$rand_keys = array_rand($inventory_ids, mt_rand(1, 5));
$detail_inventory_ids = [];
foreach ($rand_keys as $k)
$detail_inventory_ids[] = $inventory_ids[$k];
foreach ($detail_inventory_ids as $detail_inventory_id)
$detail = new \OrderDetail;
$detail->order_id = $order->id;
$detail->inventory_id = $detail_inventory_id;
$detail->qty_ordered = mt_rand(1, 10);
$detail->qty_picked = 0;
$detail->qty_packed = 0;
$detail->qty_dispatched = 0;
$detail->save();
我这样运行播种机:php artisan db:seed --class=SeedDummyOrders
当我这样做时,我收到以下错误:
"error":"type":"Symfony\Component\Debug\Exception\FatalErrorException","message":"调用 到未定义的方法 SeedDummyOrders::setContainer()","file":"C:\wamp\www\MY_PROJECT\vendor\laravel\framework\src\Illuminate\Database\Console\SeedCommand.php","line":69
任何想法这是关于什么以及如何解决它?
【问题讨论】:
【参考方案1】:好吧,我犯了一个愚蠢的错误。我忘了用 DatabaseSeeder 扩展这个类。
现在可以了。
【讨论】:
【参考方案2】:我有同样的问题。运行composer dumpautoload
后,我收到以下消息:
vagrant@vagrant:/vagrant/getrileynow$ composer dumpautoload
Generating autoload files
Warning: Ambiguous class resolution, "GenerateEmailFilters" was found in both "/vagrant/project/database/migrations/2017_02_26_033525_generate_email_filters.php" and "/vagrant/project/database/seeds/GenerateEmailFilters.php", the first will be used.
将播种器文件重命名为其他文件后,我能够运行迁移。
【讨论】:
以上是关于Laravel4 数据库播种器错误 - 调用未定义的方法 SeedDummyOrders::setContainer()的主要内容,如果未能解决你的问题,请参考以下文章
Bcrypt 在 Lumen 5.4 中不起作用:调用未定义的函数 bcrypt()
PHP 致命错误:调用未定义函数 apache_getenv()