【laravel5.1-0.0.5】基础3 数据库配置与使用mi

2015-10-16  本文已影响283人  dingyiming

预备

数据库配置 .env

配置文件在项目根目录下,新建或修改(可复制存在的 .env.example)

DB_HOST=localhost
DB_DATABASE=blog
DB_USERNAME=root
DB_PASSWORD=
DB_HOST=localhost
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

Migations生成数据表

1.新建articles表迁移(预备生成的表及内容)

2.添加表字段及属性

public function up()
{    
    Schema::create('articles', function (Blueprint $table) {        
        $table->increments('id');// 主键 自增        
        $table->string('title');        
        $table->text('content');        
        $table->timestamps(); // 自动创建的两个字段:created_at 和 updated_at,记录创建时间和更新时间    
    });
}
public function down()
{    
    Schema::drop('articles');
}

3.运行迁移

4. 回滚迁移

详情看这里 :

命令行创建Model(备用)

上一篇 下一篇

猜你喜欢

热点阅读