私はmysqlデータベースとlaravelがセットアップされたeasyPHP開発サーバーを持っています。データベースに「properties」と「property_images」という 2 つのテーブルを設定するために、2 つの移行を実行しました。
properties と property_images 用に作成された 2 つのモデルがあります。
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
すると、ファイルが実行され、「Finished property table delete」の前にすべてが出力され、その後は何も出力されません。ループに陥っているように、コマンドを終了することはありません。シード ファイル:
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