Laravel 创建指定表 migrate命令

网上找了很多资料,都很坑爹,说是要把之前的表都给删掉,然后重新运行,有的说要指定database的文件路径,都不管用。

php artisan migrate:reset
php artisan migrate

这样的话我之前的数据不都是白搞的了??
这样肯定不行的啊,我就自己摸索,然后发现其实可以直接创建指定的表,运行thinker,然后运行up方法即可!

示例代码如下:

    public function up() {
       Schema::create('table_admin', function (Blueprint $table) {
            $table->increments('id');
            $table->string('nickname',30)->default('')->comment("昵称");
            $table->string('username',50)->default('')->comment("登录帐号");
            $table->string('roles',20)->default('')->comment("角色(administer:系统管理员,manage:企业管理员)");
            $table->string('mobile',20)->default('')->comment("手机");
            $table->string('email',60)->default('')->comment("邮箱");
            $table->string('avatar',20)->default('')->comment("头像(系统自带的头像图标)");
            $table->string('password',60)->default('')->comment("密码");
            $table->string('salt',10)->default('')->comment("6位英文加盐值,首次创建随机生成");
            $table->bigInteger('dateline',10)->default(0)->comment("注册时间");
            $table->bigInteger('uptime',10)->default(0)->comment("修改时间");
            $table->tinyInteger('is_enabled',1)->default(0)->comment("是否已启用(0:否,1:是)");
            $table->tinyInteger('is_deleted',1)->default(0)->comment("是否已删除(0:否,1:是)");
            $table->timestamps();
        });
    }

这个需要设置composer.json里面的自动加载,需要加载database/migrations这个文件夹下面的文件:

....
    "autoload": {
        "classmap": [
            "database/seeds",
            "database/migrations",
            "database/factories"
        ]
    },
....
PS D:\phpStudy\WWW\BCCAdminV1.0> php artisan tinker
Psy Shell v0.7.2 (PHP 7.1.9 — cli) by Justin Hileman
>>> (new CreateTableAdmin)->up();
=> null
>>>          

运行出来个null,我还想着估计完蛋了,但是i还是去数据库看了一眼,你猜怎么着,还真的成功了!

批量生成测试数据

https://blog.csdn.net/websites/article/details/89207076

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

云尔Websites

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值