Laravel 5数据库 数据库迁移案例2——创建数据结构,数据表,修改数据结构

把数据库配置的地方改到了 learnlaravel5/.env,打开这个文件,编辑下面四项,修改为正确的信息:
DB_HOST=localhost
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(11NOT 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(255NOT NULL,

Create a numeric column called age (explicitly allow NULL values):

$t->integer('age')->nullable();

This generates the SQL:

`age` INT(11NULL 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(4NOT 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(10UNSIGNED 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',
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值