首页 > 后端开发 > php教程 > Laravel5.5执行表迁移命令出现表为空的解决方案

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

不言
发布: 2023-04-02 16:28:01
原创
2188 人浏览过

这篇文章主要介绍了关于Laravel5.5执行表迁移命令出现表为空的解决方案,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下

今天在使用一个第三方包 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

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;

class CreateAdminTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        $connection = config(&#39;admin.database.connection&#39;) ?: config(&#39;database.default&#39;);

       // dd(app(&#39;config&#39;));
        Schema::connection($connection)->create(config(&#39;admin.database.users_table&#39;), function (Blueprint $table) {
            $table->increments(&#39;id&#39;);
            $table->string(&#39;username&#39;, 190)->unique();
            $table->string(&#39;password&#39;, 60);
            $table->string(&#39;name&#39;);
            $table->string(&#39;avatar&#39;)->nullable();
            $table->string(&#39;remember_token&#39;, 100)->nullable();
            $table->timestamps();
        });

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

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

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

            $table->timestamps();
        });

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

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

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

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

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

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

        Schema::connection($connection)->dropIfExists(config(&#39;admin.database.users_table&#39;));
        Schema::connection($connection)->dropIfExists(config(&#39;admin.database.roles_table&#39;));
        Schema::connection($connection)->dropIfExists(config(&#39;admin.database.permissions_table&#39;));
        Schema::connection($connection)->dropIfExists(config(&#39;admin.database.menu_table&#39;));
        Schema::connection($connection)->dropIfExists(config(&#39;admin.database.user_permissions_table&#39;));
        Schema::connection($connection)->dropIfExists(config(&#39;admin.database.role_users_table&#39;));
        Schema::connection($connection)->dropIfExists(config(&#39;admin.database.role_permissions_table&#39;));
        Schema::connection($connection)->dropIfExists(config(&#39;admin.database.role_menu_table&#39;));
        Schema::connection($connection)->dropIfExists(config(&#39;admin.database.operation_log_table&#39;));
    }
}
登录后复制

清除配置文件缓存

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$
登录后复制

以上就是本文的全部内容,希望对大家的学习有所帮助,更多相关内容请关注PHP中文网!

相关推荐:

laravel+Redis简单实现队列通过压力测试的高并发处理

对于nginx配置文件中的fastcgi_param的配置错误的解决

以上是Laravel5.5执行表迁移命令出现表为空的解决方案的详细内容。更多信息请关注PHP中文网其他相关文章!

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
作者最新文章
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板