首页 > 编程 > PHP > 正文

Laravel 创建指定表 migrate的例子

2019-11-21 19:48:09
字体:
来源:转载
供稿:网友

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

php artisan migrate:resetphp artisan migrate

这样的话我之前的数据不都是白搞的了??

这样肯定不行的啊,我就自己摸索,然后发现其实可以直接创建指定的表,运行thinker,然后运行up方法即可!示例代码如下:

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

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

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

  public function up() {    // Schema::dropIfExists('users');    Schema::create('access_logs', function (Blueprint $table) {      $table->increments('id');      $table->string('ip')->default('0')->comment('ip地址');      $table->integer('customer_id')->default('0')->comment('用户ID');      $table->string('refer_website')->default('')->comment('来源网站');      $table->string('broswer')->default('')->comment('客户端浏览器');      $table->string('operating_system')->default('')->comment('客户端操作系统');      $table->string('resolution')->default('')->comment('客户端分辨率');      $table->string('visited_page')->default('')->comment('被访问的页面');      $table->timestamp('created_at');      $table->timestamp('left_at');    });  }

批量生成假数据:

https://www.VeVB.COm/article/171449.htm

以上这篇Laravel 创建指定表 migrate的例子就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持武林网。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表