移植
<?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
它不会抛出错误但是当我检查数据库时,来自播种机的数据不会插入到表中?
我错过了吗?因为我的代码中没有看到错误:(
答案 0 :(得分:4)
您必须将播种机添加到主播种机:DatabaseSeeder.php
<?php
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$this->call(PlayersSeeder::class);
}
}