我有一个easyPHP开发服务器,有一个mysql数据库和laravel设置。我已经运行了两次迁移以在数据库中设置两个表,"属性"和"property_images"。
我有两个用于属性和property_images的模型。
属性.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.1VC11datalocalwebprojectscwa>php
artisan db:seed
Failed loading D:PROGRA~2EASYPH~1.1VCbinariesphpphp_runningversionphp_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.1VC11datalocalw
ebprojectscwavendorlaravelframeworksrcIlluminateDatabaseEloquentModel.
php on line 615
为了进行测试,请将以下行添加到您的 DatabaseSeeder 中:
DB::disableQueryLog();
以前
$this->command->info('Starting');
通常这会使php内存耗尽的错误消失。