網(wǎng)上找了很多資料,都很坑爹,說是要把之前的表都給刪掉,然后重新運(yùn)行,有的說要指定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)行出來個(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('來源網(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('被訪問的頁(yè)面'); $table->timestamp('created_at'); $table->timestamp('left_at'); }); }
批量生成假數(shù)據(jù):
https://www.jb51.net/article/171449.htm
以上這篇Laravel 創(chuàng)建指定表 migrate的例子就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
標(biāo)簽:山南 烏魯木齊 三亞 鷹潭 南寧 赤峰 迪慶 濟(jì)寧
巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Laravel 創(chuàng)建指定表 migrate的例子》,本文關(guān)鍵詞 Laravel,創(chuàng)建,指定,表,migrate,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。