文件迁移
创建
php artisan make:migration create_paper_table
编写
public function up()
{
Schema::create('paper',function(Blueprint $table){
$table->increments('id');
$table->string('paper_name','100')->notNull()->unique();
$table->tinyInteger('total_score')->default(100);
//nullable 允许该类型为空
$table->integer('start_time')->nullable();
$table->tinyInteger('duration');
$table->tinyInteger('status')->default(1);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('paper');
}
执行
php artisan migrate:install(第一次执行的才需要做)
按照批次
php artisan migrate 建表
php artisan migrate:rollback 删除表
数据填充
创建
php artisan make:seeder PaperTableSeeder
编写
public function run()
{
$data=[
[
'paper_name'=>'JAVA',
'start_time'=>time(),
'duration'=>'120'
],
[
'paper_name'=>'PHP',
'start_time'=>time(),
'duration'=>'120'
],
[
'paper_name'=>'C++',
'start_time'=>time(),
'duration'=>'120'
]
];
DB::table('paper')->insert($data);
}
执行
php artisan db:seed --class=PaperTableSeeder
Class PaperTableSeeder does not exist解决办法
composer dump-autoload