开发者社区> 天隆金> 正文

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

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
Rainbond 部署自动初始化Schema的数据库
本文介绍在Rainbond中如何管理部署一个自动化创建Schema的方法,适用于大多数项目数据库的管理。该方式在原生容器化管理场景中有效。
747 0
【数据库】C#创建项目简单开发实现数据库表记录迁移功能
在实际项目中,很大可能会遇到数据迁移的情况 特别是对于系统升级或者旧表转移到新表,新旧表很可能是字段都不一样的情况,本篇文章就是在两个不同数据库不同表之间数据整合 同时也回顾下ADO.NET的ORM框架基础知识
31 0
使用 NineData GUI 创建与修改 ClickHouse 表结构
当前 NineData 已经完全适配支持 ClickHouse 所有表引擎的新建及其变更,在集群与分布式表的新建支持上更是做了联动优化,进一步帮助广大开发者提升效率,减少不一致现象的出现。未来,我们将继续迭代优化支持本地表与分布式表的一键联动更新,NineData 让每个人用好数据和云。
41 0
《干货分享》分区表改造(脚本模板生成),值得收藏起来实战再用
太久没有更新技术博客,后续还是保持以前的更新速度,走向新的的学习之路,也欢迎大家一起来学习学习
127 0
前端培训-中级阶段(51)- nodeJS操作,MongoDB,文档CURD操作
前端最基础的就是 HTML+CSS+Javascript。掌握了这三门技术就算入门,但也仅仅是入门,现在前端开发的定义已经远远不止这些。前端小课堂(HTML/CSS/JS),本着提升技术水平,打牢基础知识的中心思想,我们开课啦(每周四)。
75 0
自然框架的源代码、Demo、数据库、配置信息管理程序下载(2011.1.7更新)
自然框架在线演示:http://demo.naturefw.com/ 目前在线演示不开放管理员账号。   自然框架的网站已经基本完成,下载就转到网站里面了,http://www.naturefw.com/down/List1.aspx 请到这里下载。
865 0
CLI使用案例3:轻松跨库查询数据并下载到本地
使用日志服务想要跨库查询? 网页控制台下载数据一页一页十分痛苦? SDK分页加格式化有些复杂? 不想写代码就可以查询数据并下载到本地? 日志服务CLI可以帮助你轻松解决这些问题.
2981 0
手工创建/删除数据库的步骤
今天和大家分享下数据库的创建和删除的步骤,里面有很多细节需要大家考虑。创建数据库不只是一个create database语句。删除数据库 drop database也不是随时都能执行的。
910 0
+关注
文章
问答
文章排行榜
最热
最新
相关电子书
更多
阿里云数据库案例集下载
立即下载
AliSQL 内核定制方案
立即下载
高可用数据库的搭建与备份恢复策略验证实战
立即下载