Laravel 创建指定表 migrate

来源:互联网 发布:收购淘宝店铺的网站 编辑:程序博客网 时间:2024/06/05 14:28

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

php artisan migrate:resetphp artisan migrate

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

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');        });    }