zoukankan      html  css  js  c++  java
  • laravel5.6 使用迁移创建表

    laravel 使用迁移创建表

    创建迁移文件
    • --table 和 --create 选项可以用于指定表名以及该迁移是否要创建一个新的数据表。这些选项只需要简单放在上述迁移命令后面并指定表名:
    php artisan make:migration create_test_users_table --create=test_users
    
    • 新的迁移位于 database/migrations 目录下,每个迁移文件名都包含时间戳从而允许 Laravel 判断其顺序。
            // 创建
            public function up()
            {
            Schema::create('test_users', function (Blueprint $table) {
                $table->increments('id');
                $table->char('no')->nullable()->comment('平台用户编号')->index('no');
                $table->string('name')->comment('姓名');
                $table->string('email')->unique()->comment('邮箱');
                $table->string('appid')->nullable()->comment('绑定微信');
                $table->string('phone')->nullable()->comment('联系电话');
                $table->string('password')->comment('密码');
                $table->string('position')->nullable()->comment('职位');
                $table->unsignedInteger('sort')->default(10)->comment('排序');
                $table->text('remark')->nullable()->comment('备注');
                $table->rememberToken();
                $table->softDeletes();
                $table->timestamps();
            });
        }
    
        /**
         * Reverse the migrations.
         * 更新修改
         * @return void
         */
        public function down()
        {
            Schema::dropIfExists('test_users');
        }
    }
    
    
    • 执行迁移文件
    php artisan migrate
    
    
    - 回滚迁移
    • 加载依赖
     composer require doctrine/dbal
    
    • 创建修改迁移文件
    <!--【注意创建的类名 列如:】-->
    php artisan make:migration update_test_users_table
    
    
    • 执行过上个迁移文件
    php artisan migrate
    
    • 使用迁移回滚操作
    //注意:rollback 只执行上次执行的迁移文件批次中的down()方法,也就是修改方法
    php artisan migrate:rollback
    
    • 操作完成
    <!-- 窗口提示-->
    Process finished with exit code 0 at 10:24:06.
    
  • 相关阅读:
    Python pip 下载速度慢? Windows 设置 国内源,用阿里云国内镜像加速
    Go timer 是如何被调度的?
    Go sync.Pool 浅析
    一次错误使用 go-cache 导致出现的线上问题
    golang面向对象分析
    一文完全掌握 Go math/rand
    这一次,彻底搞懂 Go Cond
    面试题:让你捉摸不透的 Go reslice
    当 Go struct 遇上 Mutex
    这可能是最容易理解的 Go Mutex 源码剖析
  • 原文地址:https://www.cnblogs.com/maomojun/p/9166393.html
Copyright © 2011-2022 走看看