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 ...
随机推荐
- 140. Word Break II(hard)
欢迎fork and star:Nowcoder-Repository-github 140. Word Break II 题目: Given a non-empty string s and a d ...
- phonegap(cordova) 自己定义插件代码篇(三)----支付宝支付工具整合
建议读者,先阅读官方文档,知晓其支付流程之后再来使用此代码,比方客户须要做什么,服务端须要做什么(非常重要!非常重要! 非常重要!),由于这几个篇幅都是纯代码篇,由于阅读前面的入门篇之后看这些应该毫无 ...
- Android开发人员不得不收集的代码(转)
App相关→AppUtils.java 安装App installApp 卸载指定包名的App uninstallApp 获取当前App信息 getAppInfo 获取所有已安装App信息 getAl ...
- Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental……
Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to th ...
- UNP学习笔记(第一章 简介)
环境搭建 1.下载解压unpv13e.tar.gz 2.进入目录执行 ./configurecd lib //进入lib目录make //执行make命令 3.将生成的libunp.a静态库复制到/u ...
- css样式控制元素固定在底部
回复固定在底部:css样式用到了 box-sizing属性 box-sizing:border-box; -moz-box-sizing:border-box; /* Firefox */ -webk ...
- nfs部署和优化 -2
客户端: cat /etc/passwd 显示用户 weifeng 500 服务端: vim /etc/exports /mnt 192.168.1.105(rw,sync,all_squash, ...
- lambda表达式转换sql
using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; usin ...
- jquery插件中使用ajax并且获取使用插件的对象
jquery插件中使用ajax后无法在里面获取this 解决办法是在函数内使用ajax前声明变量 $this=this 然后再ajax中使用$this
- apt-get update --> Bad header line (fresh install) Ign http://archive.ubuntu.com natty-security/multiverse Sources/DiffIndex W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/natty/Rele
apt-get update --> Bad header line (fresh install) fresh natty install i386 desktop. I get this e ...