learnlaravel5/.env
,打开这个文件,编辑下面四项,修改为正确的信息:
DB_DATABASE=laravel5
DB_USERNAME=root
DB_PASSWORD=password
数据库迁移
php artisan migrate
模型Models
php artisan make:model Image
接下来进行 Image 类对应的 Image 表的数据库迁移,进入 learnlaravel5/databases/migrations
文件夹。
在 *createimage_table.php 中修改:
Schema::create('app_configs', function(Blueprint $table){$table->increments('id'); 自增Id
$table->boolean('appid',6); Tinyint 6位
$table->string('name',100); varchar100
$table->string('token'); varchar255
$table->boolean('sm_image',2)->default(1); tinyint 2位 默认为
$table->string('image_type',50)->nullable();varchar 50 可以为空
$table->integer('create_time');int 11位
$table->integer('end_time');
});
// auto increment id (primary key)
$t->increments('id');
$t->string('name');
$t->integer('age')->nullable();
$t->boolean('active')->default(1);
$t->integer('role_id')->unsigned();
$t->text('bio');// created_at, updated_at DATETIME
$t->timestamps();
We start out by defining the primary key for our table:
$t->increments('id');
This generates the SQL:
`id` INT(11) NOT NULL AUTO_INCREMENT,
Create a column called name
with a default length of 255 (NOT NULL
constraint is implicitly enforced by Laravel):
$t->string('name');
This generates the SQL:
`name` VARCHAR(255) NOT NULL,
Create a numeric column called age
(explicitly allow NULL
values):
$t->integer('age')->nullable();
This generates the SQL:
`age` INT(11) NULL DEFAULT NULL,
Create a boolean column called active
with a default value of 1:
$t->boolean('active')->default(1);
This generates the SQL:
`active` TINYINT(4) NOT NULL DEFAULT '1',
Create a numeric column called role_id
and set it’s column type to UNSIGNED
:
$t->integer('role_id')->unsigned();
This generates the SQL:
`role_id` INT(10) UNSIGNED NOT NULL,
Create a text field named bio
:
$t->text('bio');
This generates the SQL:
`bio` TEXT NOT NULL,
Create two timestamp fields:
$t->timestamps();
This generates the SQL:
`created_at` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00',`updated_at` TIMESTAMP NOTNULL DEFAULT '0000-00-00 00:00:00',