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('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
Laravel5.5执行表迁移命令出现表为空的解决方案的更多相关文章
- 项目那几步走:先配置setting路径文件、创建数据库、执行数据库迁移命令、配置mysql数据库信息、注册app、注释中间件、pymysql替换mysqldb-配置urls路由-继续视图函数-然后HTML页面展示-HTML里面导入css文件、models配置数据库表、
django使用mysql数据库: 首先cmd创建库 1.settings: """Django settings for day42 project. Generate ...
- Django迁移命令无法生成mysql表
数据库迁移问题:在执行python manage.py makemigrations迁移命令之后,正常输出并生成迁移文件,但执行python manage.py migrate之后显示,No migr ...
- laravel5.2总结--数据迁移
迁移就像是数据库中的版本控制,它让团队能够轻松的修改跟共享应用程序的数据库结构. 1 创建一个迁移 1.1 使用artisan命令make:migration来创建一个新的迁移: ph ...
- MySQL数据库的库表迁移
最近在研究MySQL数据库的库表迁移问题,主要分为两种情况,一种情况是迁移数据库的表的全部字段,另一种是迁移数据库的表的部分字段.前一种情况是直接使用mysqldump命令来实现,后一种情况则是采用数 ...
- Entity Framework 迁移命令 详解
一.Entity Framework 迁移命令(get-help EntityFramework) Enable-Migrations 启用迁移 Add-Migration 为挂起的Model变化添加 ...
- neutron创建network执行的那些命令
当搭建完openstack之后,在创建instance之前,第一件事情就是创建network,一个经典的流程如下: TENANT_NAME="openstack"TENANT_NE ...
- oracle 表迁移方法 (二) 约束不失效
DB:11.2.0.3.0 在oracle 表迁移方法 (一)中,只是move了一张普通的表,如果表的字段带有主键约束呢 ? [oracle@db01 ~]$ sqlplus / as sysdba ...
- Oracle DB 执行表空间时间点恢复
• 列出在执行表空间时间点恢复(TSPITR) 时会发生的操作 • 阐释TSPITR 使用的术语的定义 • 确定适合将TSPITR 用作解决方案的情况 • 确定时间点恢复的正确目标时间 • 确定不能使 ...
- mysql查看表结构命令
mysql查看表结构命令 mysql查看表结构命令,如下: desc 表名;show columns from 表名;describe 表名;show create table 表名; use inf ...
随机推荐
- EasyMvc入门教程-基本控件说明(2)定时器
我们有时候希望系统能自动刷新后台数据或者做某个动作,那么定时器的作用就体现出来了. EasyMvc默认提供的服务器可以定时调前端方法与定时调后端方法,先看例子: 定时调客户端事件 实现代码: @Htm ...
- StringUtils和IOUtils工具包的使用
加载apache的工具类 <dependency> <groupId>commons-lang</groupId> <artifactId>common ...
- 第十二题 Merge Sorted Array
Given two sorted integer arrays A and B, merge B into A as one sorted array. Note: You may assume th ...
- KVO(1)
#import "ViewController.h" @interface ViewController () @property(nonatomic, strong)UIButt ...
- memcpy( )的使用以及迭代器的使用
memcpy() -- 拷贝内存内容 相关函数: bcopy(), memccpy(), memmove(), strcpy(), strncpy() 表头文件: #include <strin ...
- Xutils的get请求后,总是返回同样数据的问题解决方式
原因: XUtils中的HttpUtils框架採用的时,HttpUtils对于GET请求採用了LRU缓存处理.默认60秒内提交返回上次成功的结果. 解决方法: HttpUtils http = new ...
- TextView上的文字逐渐变淡直到消失
给TextView加个动画效果,完了在个动画加个监听,里面有个动画执行完调用的方法在方法里面把TextView设置为gone,我觉得你直接加这个动画效果之后他就会不显示了,其实他还在那占有位置呢.想不 ...
- Centos6.0使用第三方YUM源(EPEL,RPMForge,RPMFusion)
yum是centos下很方便的rpm包管理工具,配置第三方软件库使你的软件库更加丰富.以下简单的讲下配置的步骤. 首先,需要安装yum-priorities插件: yum install yum-pr ...
- Android利用reative_layout生成梅花界面
XML代码: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:and ...
- POJ 2253 Frogger(最小最大距离)
题意 给你n个点的坐标 求第1个点到第2个点的全部路径中两点间最大距离的最小值 非常水的floyd咯 #include<cstdio> #include<cmath> #i ...