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

简介: 今天在使用一个第三方包 laravel-admin 时,出现了这样的错误:SQLSTATE[42000]: Syntax error or access violation: 1103 Incorrect table name '',折腾了好久,终于知道了解决方法,原来是配置文件的缓存没有清理。
今天在使用一个第三方包 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('admin.database.connection') ?: config('database.default');

       // dd(app('config'));
        Schema::connection($connection)->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://segmentfault.com/a/1190000015532236

目录
相关文章
|
2月前
|
关系型数据库 MySQL API
实时计算 Flink版操作报错合集之同步MySQL数据到另一个MySQL数据库,第一次同步后源表数据发生变化时目标表没有相应更新,且Web UI中看不到运行的任务,该怎么解决
在使用实时计算Flink版过程中,可能会遇到各种错误,了解这些错误的原因及解决方法对于高效排错至关重要。针对具体问题,查看Flink的日志是关键,它们通常会提供更详细的错误信息和堆栈跟踪,有助于定位问题。此外,Flink社区文档和官方论坛也是寻求帮助的好去处。以下是一些常见的操作报错及其可能的原因与解决策略。
163 0
|
11月前
|
弹性计算 API 数据库
阿里云RPA的执行脚本可以操作数据库
阿里云RPA的执行脚本可以操作数据库
177 1
|
关系型数据库 MySQL PHP
PHP高级开发案例(1):使用MYSQL语句跨表查询无法导出全部记录的解决方案
PHP高级开发案例(1):使用MYSQL语句跨表查询无法导出全部记录的解决方案
73 0
|
SQL 关系型数据库 MySQL
【解决方案 二十四】如何对MySQL数据表批量执行操作
【解决方案 二十四】如何对MySQL数据表批量执行操作
151 0
|
关系型数据库 MySQL 数据库连接
关于如何使用命令行新建数据库的解决方案
关于如何使用命令行新建数据库的解决方案
133 0
|
数据库 Python
Python编程:MySQLdb模块更新数据库获取影响行数
Python编程:MySQLdb模块更新数据库获取影响行数
192 0
|
存储 JSON Linux
RavenDB起步--安装以及示例数据库
本篇是 RavenDB 起步阶段的首篇文章,我将会在这篇文章里讲解如何安装 RavenDB 以及如何创建实例数据库。下面就让我们开始吧!
112 0
RavenDB起步--安装以及示例数据库
|
SQL 存储 关系型数据库
「OushuDB」用户指南数据定义 创建和管理数据库 (上)
数据库是一些SQL对象(“数据库对象”)的集合;通常每个数据库对象(表、函数等)属于并且只属于一个数据库。不过有几个系统表 (比如pg_database)属于整个集群并且可以在集群之内的每个数据库里访问。更准确地说,一个数据库是一个模式的集合,而模式包含表、函数等等。因此完整的层次是这样的:服务器→数据库→模式→表(或者其它类型对象,比如函数)。
162 0
「OushuDB」用户指南数据定义 创建和管理数据库 (上)
|
SQL 关系型数据库 Shell
「OushuDB」用户指南数据定义 创建和管理数据库 (中)
CREATE DATABASE实际上是通过拷贝一个现有的数据库进行工作的。缺省时,它拷贝名为template1的标准系统数据库。所以该数据库是创建新数据库的”模板”。如果你给template1增加对象,这些对象将被拷贝到随后创建的用户数据库中。这样的行为允许节点对数据库中的标准套件进行修改。比如,如果你把过程语言PL/Perl安装到template1里,那么你在创建用户数据库的时候它们就会自动可得,而不需要额外的动作。
142 0
「OushuDB」用户指南数据定义 创建和管理数据库 (中)
|
Shell 数据库连接 数据库
「OushuDB」用户指南数据定义 创建和管理数据库 (下)
回顾一下 http://www.oushu.com/docs/ch/server-configuration.html 我们知道OushuDB 服务器提供了大量的运行时配置变量。你可以为许多这种变量设置特定于数据库的缺省数值。
134 0
「OushuDB」用户指南数据定义 创建和管理数据库 (下)