我有一个带有mysql数据库和laravel设置的easyPHP devserver。我已经运行了两次迁移来在数据库中设置两个表,'properties'和'property_images'。
我有两个针对属性和property_images的模型。
Property.php:
class Property extends Eloquent {
protected $fillable = array('id','title','type','description');
public function propertyImages() {
return $this->hasMany('PropertyImage');
}
}
Property_image.php:
class Property extends Eloquent {
public function property() {
return $this->belongsTo('Property');
}
}
我正在尝试使用此文件播种数据库。运行php artisan db:seed
运行文件并输出“完成属性表删除”之前的所有内容,然后不输出任何内容。它永远不会完成命令,就像它陷入循环一样。
种子档案:
class DatabaseSeeder extends Seeder {
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$this->command->info('Starting');
$this->call('PropertyTableSeeder');
$this->command->info('Finished first seed');
$this->call('PropertyImageTableSeeder');
$this->command->info('Done seeding');
}
}
class PropertyTableSeeder extends Seeder {
public function run() {
DB::table('properties')->delete();
$this->command->info('Finished Property table delete'); //This line prints out fine
Property::create(array(
'id' => 'caseyTrail1',
'title' => 'Casey Trail 1',
'type' => 'residential',
'description' => 'This is the description for Casey Trail 1.'
));
$this->command->info('Created first property'); //Never reaches this output
Property::create(array(
'id' => 'caseyTrail2',
'title' => 'Casey Trail 2',
'type' => 'residential',
'description' => 'This is the description for Casey Trail 2.'
));
Property::create(array(
'id' => 'castleResidence',
'title' => 'Castle Residence',
'type' => 'residential',
'description' => 'This is the description for Castle Residence.'
));
Property::create(array(
'id' => 'ormandBeach',
'title' => 'Ormand Beach',
'type' => 'residential',
'description' => 'This is the description for Ormand Beach.'
));
Property::create(array(
'id' => 'privateResidence1',
'title' => 'Private Residence 1',
'type' => 'residential',
'description' => 'This is the description for Private Residence 1.'
));
Property::create(array(
'id' => 'assuranceTitle',
'title' => 'Assurance Title',
'type' => 'commercial',
'description' => 'This is the description for Assurance Title.'
));
Property::create(array(
'id' => 'bethesda',
'title' => 'Bethesda',
'type' => 'commercial',
'description' => 'This is the description for Bethesda.'
));
Property::create(array(
'id' => 'choiceBank',
'title' => 'Choice Bank',
'type' => 'commercial',
'description' => 'This is the description for Choice Bank.'
));
Property::create(array(
'id' => 'dawesStreetApartments',
'title' => 'Dawes Street Apartments',
'type' => 'commercial',
'description' => 'This is the description for Dawes Street Apartments.'
));
Property::create(array(
'id' => 'dublins',
'title' => 'Dublins',
'type' => 'commercial',
'description' => 'This is the description for Dublins.'
));
Property::create(array(
'id' => 'langFinancial',
'title' => 'Lang Financial',
'type' => 'commercial',
'description' => 'This is the description for Lang FInancial.'
));
Property::create(array(
'id' => 'skiersOutlet',
'title' => 'Skiers Outlet',
'type' => 'commercial',
'description' => 'This is the description for Skiers Outlet.'
));
$this->command->info('Finished Property run');
}
}
class PropertyImageTableSeeder extends Seeder {
public function run() {
DB::table('property_images')->delete();
PropertyImage::create(array(
'property_id' => 'caseyTrail1',
'filename' => 'picture1',
'title' => 'Casey Trail 1 Picture 1'
));
PropertyImage::create(array(
'property_id' => 'caseyTrail1',
'filename' => 'picture2',
'title' => 'Casey Trail 1 Picture 2'
));
PropertyImage::create(array(
'property_id' => 'caseyTrail1',
'filename' => 'picture3',
'title' => 'Casey Trail 1 Picture 3'
));
PropertyImage::create(array(
'property_id' => 'caseyTrail2',
'filename' => 'picture1',
'title' => 'Casey Trail 2 Picture 1'
));
PropertyImage::create(array(
'property_id' => 'caseyTrail2',
'filename' => 'picture2',
'title' => 'Casey Trail 2 Picture 2'
));
PropertyImage::create(array(
'property_id' => 'caseyTrail2',
'filename' => 'picture3',
'title' => 'Casey Trail 2 Picture 3'
));
}
}
当我让命令运行一段时间后,它最终会给出错误输出:
D:\Program Files (x86)\EasyPHP-DevServer-13.1VC11\data\localweb\projects\cwa>php
artisan db:seed
Failed loading D:\PROGRA~2\EASYPH~1.1VC\binaries\php\php_runningversion\php_xdeb
ug-2.2.2-5.4-vc9.dll
Starting
Finished Property table delete
PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to all
ocate 32 bytes) in D:\Program Files (x86)\EasyPHP-DevServer-13.1VC11\data\localw
eb\projects\cwa\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.
php on line 615
答案 0 :(得分:2)
要测试,请将此行添加到您的DatabaseSeeder:
DB::disableQueryLog();
在
$this->command->info('Starting');
通常这会使php内存耗尽错误消失。