laravel使用migration建立数据表

admin2017-03-304412

首先在命令行下进入到项目根目录,执行下面命令:

php artisan make:migration create_record_table --create=record

create_record_table是laravel生成的临时用来建立数据表的文件,最后面的record是该文件被运行后在数据库里面生成的数据表的名字。

运行完成后会在laravel项目的database->migrations目录下生成create_record_table文件,文件名上有创建的时间。

然后进入该文件,填写建表的命令进行数据表设计。

class CreateRecordTable extends Migration
{
    public function up()
    {
        Schema::create('record', function (Blueprint $table) {
            $table->increments('id');    //increments自增,主键
            $table->integer('uid');      //integer类型
            $table->decimal('record',11,2);    //decimal浮点型
            $table->integer('to_lid');
            $table->integer('status');
            $table->decimal('balance',11,2);
            $table->timestamps();
        });
    }

根据数据表的需要设计完,然后执行命令:

php artisan migrate

看看数据库里是不是已经多了个record表了。

网友评论