Laravel 数据库版本管理系统

database migrationslaravel最强大的功能之一。数据库迁移可以理解为数据库的版本控制器。


 

php artisan命令行:

php artisan make:migration

 

 ps:该命令行必须在项目的根目录下执行。

如果对该命令行不是很了解,可是添加参数-h,查看说明文档。

Usage:
  make:migration [options] [--] <name>

Arguments:
  name                   The name of the migration.

Options:
      --create[=CREATE]  The table to be created.
      --table[=TABLE]    The table to migrate.
      --path[=PATH]      The location where the migration file should be created.
  -h, --help             Display this help message
  -q, --quiet            Do not output any message
  -V, --version          Display this application version
      --ansi             Force ANSI output
      --no-ansi          Disable ANSI output
  -n, --no-interaction   Do not ask any interactive question
      --env[=ENV]        The environment the command should run under.
  -v|vv|vvv, --verbose   Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Help:
 Create a new migration file

 


 

创建数据表

1.直接创建。

php artisan make:migration xxx

 

这种方式下生成的数据库表类,只有方法,没有初始化数据表的名字已经字段。

class Xxx extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        //
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        //
    }
}

 

 

2.添加参数 --create

php artisan make:migration yyyy --create='yyyy'

 这种方式下生成的数据库表类,不仅初始化了数据表的名字,同时添加了默认字段名。

class Yyyy extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create(''yyyy'', function (Blueprint $table) {
            $table->increments('id');
            $table->timestamps();
        });
    }

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

 

3.添加参数 --table

php artisan make:migration yyyyy --table='yyyyy'

 这种方式下生成的数据库表类,已经初始化数据表的名字,但是,没有默认添加字段。

class Yyyyy extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table(''yyyyy'', function (Blueprint $table) {
            //
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table(''yyyyy'', function (Blueprint $table) {
            //
        });
    }
}

不拒打赏:

  

微信

支付宝

转载于:https://www.cnblogs.com/toxufe/p/5772813.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值