• 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.
    
  • 相关阅读:
    left、pixelLeft、posLeft的区别
    mysql null 值查询问题
    把php.exe加入系统环境变量-使用命令行可快速执行PHP命令
    《软件测试》
    《软件实现》
    《面向对象设计》
    《面向对象分析》
    《面向对象基础》
    《软件工程中的形式化方法》
    《需求工程》
  • 原文地址:https://www.cnblogs.com/maomojun/p/9166393.html
Copyright © 2020-2023  润新知