laravel5.4使用migration数据库迁移建表

首先要保证laravel的.env文件中的数据库链接已经创建好,在这里我使用的是MYSQL数据库

1 DB_CONNECTION=mysql   //数据库
2 DB_HOST=127.0.0.1  //服务器IP地址
3 DB_PORT=3306    //数据库的端口
4 DB_DATABASE=larvael54  //数据库名
5 DB_USERNAME=root   //数据库用户名
6 DB_PASSWORD=root  //数据库密码

在这里我用的是PHP storm命令行 输入创建migration命令  比如创建users表

PHP artisan make:migration create_users_table

注意:创建migration文件名为create_表名_table,创建成功会在database目录下的migrations目录下创建一个

2017_12_6_205846_create_users_table.php文件,打开文件输入代码
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {  //这里是你要创建表的字段属性
            $table->increments('id'); 
            $table->string('name');
            $table->string('email')->unique();
            $table->string('password');
            $table->rememberToken();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('users');
    }
}

文件创建成功后在PHP storm命令行中输入

PHP artisan migrate

执行完成后,建表成功。

 

转载于:https://www.cnblogs.com/ywhzmr/p/7994166.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值