资讯专栏INFORMATION COLUMN

Laravel5.5执行表迁移命令出现表为空的解决方案

tolerious / 987人阅读

摘要:今天在使用一个第三方包时,出现了这样的错误折腾了好久,终于知道了解决方法,原来是配置文件的缓存没有清理。一问题错误提示二解决方案清除配置文件缓存再次执行发布命令,就可以了

今天在使用一个第三方包 laravel-admin 时,出现了这样的错误:SQLSTATE[42000]: Syntax error or access violation: 1103 Incorrect table name "",折腾了好久,终于知道了解决方法,原来是配置文件的缓存没有清理。
一、问题
vagrant@homestead:~/Code/laravel-shop$ php artisan admin:install

错误提示:

In Connection.php line 664:

  SQLSTATE[42000]: Syntax error or access violation: 1103 Incorrect table name "" (SQL: create table `` (`id` int uns
  igned not null auto_increment primary key, `username` varchar(190) not null, `password` varchar(60) not null, `name
  ` varchar(255) not null, `avatar` varchar(255) null, `remember_token` varchar(100) null, `created_at` timestamp nul
  l, `updated_at` timestamp null) default character set utf8mb4 collate utf8mb4_unicode_ci)


In Connection.php line 452:

  SQLSTATE[42000]: Syntax error or access violation: 1103 Incorrect table name ""
二、解决方案

database/migrations/2016_01_04_173148_create_admin_table.php

create(config("admin.database.users_table"), function (Blueprint $table) {
            $table->increments("id");
            $table->string("username", 190)->unique();
            $table->string("password", 60);
            $table->string("name");
            $table->string("avatar")->nullable();
            $table->string("remember_token", 100)->nullable();
            $table->timestamps();
        });

        Schema::connection($connection)->create(config("admin.database.roles_table"), function (Blueprint $table) {
            $table->increments("id");
            $table->string("name", 50)->unique();
            $table->string("slug", 50);
            $table->timestamps();
        });

        Schema::connection($connection)->create(config("admin.database.permissions_table"), function (Blueprint $table) {
            $table->increments("id");
            $table->string("name", 50)->unique();
            $table->string("slug", 50);
            $table->string("http_method")->nullable();
            $table->text("http_path")->nullable();
            $table->timestamps();
        });

        Schema::connection($connection)->create(config("admin.database.menu_table"), function (Blueprint $table) {
            $table->increments("id");
            $table->integer("parent_id")->default(0);
            $table->integer("order")->default(0);
            $table->string("title", 50);
            $table->string("icon", 50);
            $table->string("uri", 50)->nullable();

            $table->timestamps();
        });

        Schema::connection($connection)->create(config("admin.database.role_users_table"), function (Blueprint $table) {
            $table->integer("role_id");
            $table->integer("user_id");
            $table->index(["role_id", "user_id"]);
            $table->timestamps();
        });

        Schema::connection($connection)->create(config("admin.database.role_permissions_table"), function (Blueprint $table) {
            $table->integer("role_id");
            $table->integer("permission_id");
            $table->index(["role_id", "permission_id"]);
            $table->timestamps();
        });

        Schema::connection($connection)->create(config("admin.database.user_permissions_table"), function (Blueprint $table) {
            $table->integer("user_id");
            $table->integer("permission_id");
            $table->index(["user_id", "permission_id"]);
            $table->timestamps();
        });

        Schema::connection($connection)->create(config("admin.database.role_menu_table"), function (Blueprint $table) {
            $table->integer("role_id");
            $table->integer("menu_id");
            $table->index(["role_id", "menu_id"]);
            $table->timestamps();
        });

        Schema::connection($connection)->create(config("admin.database.operation_log_table"), function (Blueprint $table) {
            $table->increments("id");
            $table->integer("user_id");
            $table->string("path");
            $table->string("method", 10);
            $table->string("ip", 15);
            $table->text("input");
            $table->index("user_id");
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        $connection = config("admin.database.connection") ?: config("database.default");

        Schema::connection($connection)->dropIfExists(config("admin.database.users_table"));
        Schema::connection($connection)->dropIfExists(config("admin.database.roles_table"));
        Schema::connection($connection)->dropIfExists(config("admin.database.permissions_table"));
        Schema::connection($connection)->dropIfExists(config("admin.database.menu_table"));
        Schema::connection($connection)->dropIfExists(config("admin.database.user_permissions_table"));
        Schema::connection($connection)->dropIfExists(config("admin.database.role_users_table"));
        Schema::connection($connection)->dropIfExists(config("admin.database.role_permissions_table"));
        Schema::connection($connection)->dropIfExists(config("admin.database.role_menu_table"));
        Schema::connection($connection)->dropIfExists(config("admin.database.operation_log_table"));
    }
}

清除配置文件缓存

vagrant@homestead:~/Code/laravel-shop$ php artisan config:cache

再次执行发布命令,就可以了:

vagrant@homestead:~/Code/laravel-shop$ php artisan admin:install
Migrating: 2016_01_04_173148_create_admin_table
Migrated:  2016_01_04_173148_create_admin_table
Admin directory was created: /app/Admin
HomeController file was created: /app/Admin/Controllers/HomeController.php
ExampleController file was created: /app/Admin/Controllers/ExampleController.php
Bootstrap file was created: /app/Admin/bootstrap.php
Routes file was created: /app/Admin/routes.php
vagrant@homestead:~/Code/laravel-shop$

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/28973.html

相关文章

  • windows下laravel5.5手写教程1(适合初学者)

    摘要:打开浏览器输入,如无意外,将出现如下图,表示框架安装成功。四系统内部后台管理系统这个是框架自带的后台登录管理系统,只需要简单的命令即可运行。出现上图即为,创建模型成功。 在PHP个各种web开发框架中,laravel算是一款简洁、优雅的开发框架,本人也刚刚接触到laravel,通过学习大神们的一些文章,下面是我的一些心得体会,希望可以给初学者一些帮助,大家一起进步。言归正传: 本人环境...

    GeekGhc 评论0 收藏0
  • 用 JavaScript 实现链操作 - 10 Move Node In-place

    摘要:需求实现一个函数,把源链表的头结点移到目标链表的开头。要求是不能修改两个链表的引用。跟前一个不同的是,这个是在不改变引用的情况下修改两个链表自身。最优的方案这个算法考的是对链表节点的插入和删除。大致思路为对做删除一个节点的操作。 TL;DR 用 in-place 的方式把一个链表的首节点移到另一个链表(不改变链表的引用),系列目录见 前言和目录 。 需求 实现一个 moveNode()...

    CNZPH 评论0 收藏0
  • 用 JavaScript 实现链操作 - 13 Shuffle Merge

    摘要:需求实现函数把两个链表合并成一个。新链表的节点是交叉从两个链表中取的。通过行的调换指针,我们可以保证下一次循环就是对另一个链表进行操作了。这样一直遍历到两个链表末尾,返回结束。参考资料的代码实现的测试 TL;DR 把两个链表洗牌合并成一个,系列目录见 前言和目录 。 需求 实现函数 shuffleMerge() 把两个链表合并成一个。新链表的节点是交叉从两个链表中取的。这叫洗牌合并。举...

    shiguibiao 评论0 收藏0
  • laravel5.5 + react完成简单的CRUD

    摘要:完成简单的在这篇文章中,我想和大家分享如何在框架中使用来创建应用程序。在这个例子中,您可以学习如何为应用程序构建设置,我还使用请求,获取请求,放入请求和删除请求来插入更新删除应用程序。 laravel5.5 + react完成简单的CRUD 在这篇文章中,我想和大家分享如何在PHP Laravel框架中使用js来创建crud(Create Read Update Delete)应用程序...

    2501207950 评论0 收藏0
  • [Leetcode] Rotate List 旋转链

    摘要:不过,由于可能大于链表的长度,所以我们要先对取链表长度的模。代码计算链表长度如果不旋转或者原链表为空则直接返回让快指针先走步找到新头节点的前一个节点将后半部分放到前面来 Rotate List Given a list, rotate the list to the right by k places, where k is non-negative. For example: Gi...

    Yu_Huang 评论0 收藏0

发表评论

0条评论

最新活动
阅读需要支付1元查看
<