How to fix the quot;Base table or view not found: 1146quot; error when running #39;php artisan migrate#39; command?(如何修复“找不到基表或视图:1146运行“php artisan migrate命令时出错?)
问题描述
我正在尝试使用 rum php artisan migrate
来生成表迁移,但出现错误:
I am trying to rum php artisan migrate
to generate table migration, but I am getting an error:
[2016-03-08 05:49:01] local.ERROR: 异常 'PDOException' with消息SQLSTATE[42S02]:未找到基表或视图:1146 表'testing.permissions' 不存在'D:xampphtdocsLMS-testingvendorlaravelframeworksrcIlluminateDatabaseConnection.php:333
[2016-03-08 05:49:01] local.ERROR: exception 'PDOException' with message 'SQLSTATE[42S02]: Base table or view not found: 1146 Table 'testing.permissions' doesn't exist' in D:xampphtdocsLMS-testingvendorlaravelframeworksrcIlluminateDatabaseConnection.php:333
我尝试过 未找到基表或视图:1146 表 Laravel 5 和 正在做 Laravel 教程,得到未找到基表或视图:1146 表 'sdbd_todo.migrations' 不存在" 但没有成功.
I have tried Base table or view not found: 1146 Table Laravel 5 and Doing a Laravel tutorial, getting "Base table or view not found: 1146 Table 'sdbd_todo.migrations' doesn't exist" but did not succeed.
我也试过运行 php artisan list
但得到同样的错误.
I have also tried to run php artisan list
but getting the same error.
更新
**RolesPermission migration table**
Schema::create('roles', function(Blueprint $table){
$table->increments('id');
$table->string('name')->unique();
$table->string('label');
$table->string('description')->nullable();
$table->timestamps();
});
Schema::create('permissions', function(Blueprint $table){
$table->increments('id');
$table->string('name')->unique();
$table->string('label');
$table->string('description')->nullable();
$table->timestamps();
});
Schema::create('permission_role', function(Blueprint $table){
$table->integer('permission_id')->unsigned();
$table->integer('role_id')->unsigned();
$table->foreign('permission_id')
->references('id')
->on('permissions')
->onDelete('cascade');
$table->foreign('role_id')
->references('id')
->on('roles')
->onDelete('cascade');
$table->primary(['permission_id', 'role_id']);
});
Schema::create('role_user', function(Blueprint $table){
$table->integer('role_id')->unsigned();
$table->integer('user_id')->unsigned();
$table->foreign('role_id')
->references('id')
->on('roles')
->onDelete('cascade');
$table->foreign('user_id')
->references('id')
->on('users')
->onDelete('cascade');
$table->primary(['role_id', 'user_id']);
});
.env file
APP_ENV=local
APP_DEBUG=true
APP_KEY=W8YWZe3LCngvZzexH3WLWqCDlYRSufuy
DB_HOST=127.0.0.1
DB_DATABASE=testing
DB_USERNAME=root
DB_PASSWORD=
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_DRIVER=log
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
推荐答案
检查你的迁移文件,也许你正在使用 Schema::table,像这样:
Check your migration file, maybe you are using Schema::table, like this:
Schema::table('table_name', function ($table) {
// ...
});
如果你想创建一个新表,你必须使用 Schema::create:
If you want to create a new table you must use Schema::create:
Schema::create('table_name', function ($table) {
// ...
});
Laracast 更多信息这个链接.
这篇关于如何修复“找不到基表或视图:1146"运行“php artisan migrate"命令时出错?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何修复“找不到基表或视图:1146"运行“ph
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- PHP - if 语句中的倒序 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01