php artisan make:migration create_students_table
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateStudentsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
// students为表名称
Schema::create('students', function (Blueprint $table) {
// 存储引擎
$table->engine = 'InnoDB';
// id自增
$table->increments('id');
// 学生名称
$table->string('name');
// 性别
$table->string('sex');
// 邮箱
$table->string('email');
// 喜爱的颜色
$table->string('favorite_color');
// 手机号
$table->string('phone');
// 地址
$table->string('addr');
// 自动维护时间戳
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('students');
}
}
php artisan migrate
[Illuminate\Database\QueryException] SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was t oo long; max key length is 767 bytes (SQL: alter table users add unique users_email_unique(email)) [PDOException] SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was t oo long; max key length is 767 bytes
'charset' => 'utf8', 'collation' => 'utf8_unicode_ci',
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
/**
* 学生模型
*/
class Student extends Model
{
}
php artisan make:seed StudentsTableSeeder
<?php
use Illuminate\Database\Seeder;
class StudentsTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
// 调用模型工厂 生成10000条数据
factory(App\Student::class, 10000)->create();
}
}
<?php
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
// 调用学生表填充文件
$this->call(StudentsTableSeeder::class);
}
}
php artisan make:factory StudentsFactory -m Student
<?php
use Faker\Generator as Faker;
/* @var Illuminate\Database\Eloquent\Factory $factory */
$factory->define(App\Student::class, function (Faker $faker) {
$sex = rand(1, 1000);
return [
'name' => $faker->name,
'sex' => $sex % 2 == 0 ? '男' : '女',
'email' => $faker->unique()->safeEmail,
'favorite_color' => $faker->safeColorName,
'phone' => $faker->phoneNumber,
'addr' => $faker->address,
];
});
public function boot()
{
// 填充中文数据
$this->app->singleton(\Faker\Generator::class, function () {
return \Faker\Factory::create('zh_CN');
});
}
composer dump-autoload
[ReflectionException] Class StudentsTableSeeder does not exist
php artisan db:seed
| id | name | sex | favorite_color | phone | addr | created_at | updated_at | |
|---|---|---|---|---|---|---|---|---|
| 10000 | 谈英 | 男 | cum_et@example.com | 白色 | 17642207316 | 贵阳海陵区 | 2017-10-28 05:19:10 | 2017-10-28 05:19:10 |
| 9999 | 汤淑珍 | 男 | qlaudantium@example.net | 黑色 | 18239453935 | 南宁友好区 | 2017-10-28 05:19:10 | 2017-10-28 05:19:10 |
| 9998 | 贾春梅 | 男 | ea35@example.com | 粟色 | 17103645128 | 长沙萧山区 | 2017-10-28 05:19:10 | 2017-10-28 05:19:10 |
| 9997 | 季志明 | 男 | cdeleniti@example.com | 灰色 | 17002359608 | 天津花溪区 | 2017-10-28 05:19:10 | 2017-10-28 05:19:10 |
| 9996 | 成燕 | 男 | aspernatur.aut@example.com | 黄色 | 17181193397 | 贵阳锡山区 2017-10-28 05:19: | 10 | 2017-10-28 05:19:10 |
| 9995 | 米博 | 男 | reprehenderit_autem@example.com | 紫 | 17187328893 | 广州东丽区 | 2017-10-28 05:19:10 | 2017-10-28 05:19:10 |
| 9994 | 兰淑兰 | 女 | et_ea@example.com | 绿色 | 18592254358 | 兰州经济开发新区 | 2017-10-28 05:19:10 | 2017-10-28 05:19:10 |
| 9993 | 乐瑶 | 女 | vel.vitae@example.org | 藏青 | 15891490007 | 香港龙潭区 2017-10-28 05:19: | 10 | 2017-10-28 05:19:10 |
| 9992 | 叶志新 | 女 | lcumque@example.net | 藏青 | 15564391466 | 北京高明区 | 2017-10-28 05:19:10 | 2017-10-28 05:19:10 |
| 9991 | 胥杨 | 男 | voluptatem00@example.com | 黄色 | 17097722096 | 郑州新城区 | 2017-10-28 05:19:10 | 2017-10-28 05:19:10 |
| 9990 | 凌敏 | 女 | magni22@example.org | 鲜绿色 | 13021578051 | 杭州涪城区 | 2017-10-28 05:19:10 | 2017-10-28 05:19:10 |
| 9989 | 席建 | 女 | fugiat_accusantium@example.net | 紫 | 18070573726 | 南昌海陵区 | 2017-10-28 05:19:10 | 2017-10-28 05:19:10 |
| 9988 | 聂新华 | 女 | debitis_sapiente@example.com | 水色 | 17004061646 | 成都南长区 | 2017-10-28 05:19:10 | 2017-10-28 05:19:10 |
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有