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.
    
  • 相关阅读:
    1 step / 2 step STO
    关于Shipping
    Retail Article Master Data 学习 (四) Assortment
    SAP Basis 性能分析 记忆点
    从数据库中读取二进制数据,并显示图片
    [转]c#金山词霸组件法
    C# 处理INI文个类 INIManager
    C#实现通过HttpWebRequest发送POST请求实现网站自动登陆
    XPath语法参考
    关于IE6和IE7关闭窗口时提示和不提示以及上传图片前的本地预览解决办法
  • 原文地址:https://www.cnblogs.com/maomojun/p/9166393.html
Copyright © 2011-2022 走看看