Laravel4 数据库播种器错误 - 调用未定义的方法 SeedDummyOrders::setContainer()
Laravel4 Database Seeder error - Call to undefined method SeedDummyOrders::setContainer()
我的数据库中有两个表:
- order_header
- order_details
我需要一些虚拟数据,所以我创建了以下 SeedDummyOrders class:
<?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":"Call
to undefined method
SeedDummyOrders::setContainer()","file":"C:\wamp\www\MY_PROJECT\vendor\laravel\framework\src\Illuminate\Database\Console\SeedCommand.php","line":69}}
知道这是怎么回事吗?如何解决?
好吧,我犯了一个愚蠢的错误。我忘了用 DatabaseSeeder.
扩展这个 class
现在可以了。
我遇到了同样的问题。一旦我 运行 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.
将种子文件重命名为其他文件后,我能够运行迁移。
我的数据库中有两个表:
- order_header
- order_details
我需要一些虚拟数据,所以我创建了以下 SeedDummyOrders class:
<?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":"Call to undefined method SeedDummyOrders::setContainer()","file":"C:\wamp\www\MY_PROJECT\vendor\laravel\framework\src\Illuminate\Database\Console\SeedCommand.php","line":69}}
知道这是怎么回事吗?如何解决?
好吧,我犯了一个愚蠢的错误。我忘了用 DatabaseSeeder.
扩展这个 class现在可以了。
我遇到了同样的问题。一旦我 运行 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.
将种子文件重命名为其他文件后,我能够运行迁移。