2016-08-04 210 views
1

遷移laravel 5.2種子不工作

<?php 

use Illuminate\Database\Schema\Blueprint; 
use Illuminate\Database\Migrations\Migration; 

class CreatePlayersTable extends Migration 
{ 
    public function up() 
    { 
     Schema::create('players', function (Blueprint $table) { 
      $table->increments('id'); 
      $table->string('username'); 
      $table->boolean('status')->default(1); // True 
      $table->timestamps(); 
      $table->softDeletes(); 
     }); 
    } 

    public function down() 
    { 
     Schema::drop('players'); 
    } 
} 

模型

<?php 

namespace App; 

use Illuminate\Database\Eloquent\Model; 
use Illuminate\Database\Eloquent\SoftDeletes; 

class Player extends Model 
{ 
    use SoftDeletes; 

    protected $table = 'players'; 
    protected $fillable = ['id', 'username', 'status']; 
    protected $dates = ['deleted_at']; 
} 

播種機

<?php 

use Illuminate\Database\Seeder; 
use Carbon\Carbon as Carbon; 

class PlayersSeeder extends Seeder 
{ 
    public function run() 
    { 
     DB::table('players')->insert([ 
      [ 
       'id' => 1, 
       'username' => 'EKBD0223', 
       'status' => 0, 
       'created_at' => Carbon::now(), 
       'updated_at' => Carbon::now(), 
       'deleted_at' => NULL, 
      ] 
     ]); 
    } 
} 

爲什麼運行時php artisan db:seed它不會引發錯誤,但是當我檢查數據庫時,播種機中的數據不會在表中插入? 我有錯過嗎?因爲我沒有看到在我的代碼:(

回答

2

錯誤你必須播種機添加到主播種機:DatabaseSeeder.php

<?php 

use Illuminate\Database\Seeder; 

class DatabaseSeeder extends Seeder 
{ 
    /** 
    * Run the database seeds. 
    * 
    * @return void 
    */ 
    public function run() 
    { 
     $this->call(PlayersSeeder::class); 
    } 
} 
+0

我看到所以這是一個我忘了感謝! – Jefsama