Laravel 創(chuàng)建指定表 migrate的例子
網(wǎng)上找了很多資料,都很坑爹,說是要把之前的表都給刪掉,然后重新運行,有的說要指定database的文件路徑,都不管用。
php artisan migrate:reset php artisan migrate
這樣的話我之前的數(shù)據(jù)不都是白搞的了??
這樣肯定不行的啊,我就自己摸索,然后發(fā)現(xiàn)其實可以直接創(chuàng)建指定的表,運行thinker,然后運行up方法即可!示例代碼如下:
這個需要設置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 CreateAccessLogsTable)->up(); => null >>>
運行出來個null,我還想著估計完蛋了,但是i還是去數(shù)據(jù)庫看了一眼,你猜怎么著,還真的成功了!
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('來源網(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('被訪問的頁面'); $table->timestamp('created_at'); $table->timestamp('left_at'); }); }
批量生成假數(shù)據(jù):
http://chabaoo.cn/article/171449.htm
以上這篇Laravel 創(chuàng)建指定表 migrate的例子就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
tp5(thinkPHP5)框架實現(xiàn)多數(shù)據(jù)庫查詢的方法
這篇文章主要介紹了tp5(thinkPHP5)框架實現(xiàn)多數(shù)據(jù)庫查詢的方法,結合實例形式分析了thinkPHP5框架多數(shù)據(jù)庫查詢的相關配置、初始化及調用相關操作技巧,需要的朋友可以參考下2019-01-01