欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Laravel 創(chuàng)建指定表 migrate的例子

 更新時(shí)間:2019年10月09日 09:01:37   作者:SHUIPING_YANG  
今天小編就為大家分享一篇Laravel 創(chuàng)建指定表 migrate的例子,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧

網(wǎng)上找了很多資料,都很坑爹,說(shuō)是要把之前的表都給刪掉,然后重新運(yùn)行,有的說(shuō)要指定database的文件路徑,都不管用。

php artisan migrate:reset
php artisan migrate

這樣的話我之前的數(shù)據(jù)不都是白搞的了??

這樣肯定不行的啊,我就自己摸索,然后發(fā)現(xiàn)其實(shí)可以直接創(chuàng)建指定的表,運(yùn)行thinker,然后運(yùn)行up方法即可!示例代碼如下:

這個(gè)需要設(shè)置composer.json里面的自動(dòng)加載,需要加載database/migrations這個(gè)文件夾下面的文件:

....
  "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 CreateAccessLogsTable)->up();
=> null
>>>  

運(yùn)行出來(lái)個(gè)null,我還想著估計(jì)完蛋了,但是i還是去數(shù)據(jù)庫(kù)看了一眼,你猜怎么著,還真的成功了!

  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('來(lái)源網(wǎng)站');
      $table->string('broswer')->default('')->comment('客戶端瀏覽器');
      $table->string('operating_system')->default('')->comment('客戶端操作系統(tǒng)');
      $table->string('resolution')->default('')->comment('客戶端分辨率');
      $table->string('visited_page')->default('')->comment('被訪問(wèn)的頁(yè)面');
      $table->timestamp('created_at');
      $table->timestamp('left_at');
    });
  }

批量生成假數(shù)據(jù):

http://www.dbjr.com.cn/article/171449.htm

以上這篇Laravel 創(chuàng)建指定表 migrate的例子就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論