奇怪的事情正在发生。尝试使用php artisan migrate
运行迁移,但是对于丢失的表(应该由迁移创建和填充)会收到以下错误。
PHP Fatal error: Uncaught PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'app.portals' doesn't exist in /home/daniel/Programming/app/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:80
Stack trace:
#0 /home/daniel/Programming/app/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php(80): PDO->prepare('select * from `...', Array)
#1 /home/daniel/Programming/app/vendor/laravel/framework/src/Illuminate/Database/Connection.php(326): Doctrine\DBAL\Driver\PDOConnection->prepare('select * from `...')
#2 /home/daniel/Programming/app/vendor/laravel/framework/src/Illuminate/Database/Connection.php(657): Illuminate\Database\Connection->Illuminate\Database\{closure}('select * from `...', Array)
#3 /home/daniel/Programming/app/vendor/laravel/framework/src/Illuminate/Database/Connection.php(624): Illuminate\Database\Connection->runQueryCallback('select * from `...', Array, Object(Closure))
#4 /home/daniel/Programming/app/vendor/laravel in /home/daniel/Programming/app/vendor/laravel/framework/src/Illuminate/Database/Connection.php on line 664
PHP Fatal error: Uncaught PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'app.portals' doesn't exist in /home/daniel/Programming/app/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:80
Stack trace:
#0 /home/daniel/Programming/app/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php(80): PDO->prepare('select * from `...', Array)
#1 /home/daniel/Programming/app/vendor/laravel/framework/src/Illuminate/Database/Connection.php(326): Doctrine\DBAL\Driver\PDOConnection->prepare('select * from `...')
#2 /home/daniel/Programming/app/vendor/laravel/framework/src/Illuminate/Database/Connection.php(657): Illuminate\Database\Connection->Illuminate\Database\{closure}('select * from `...', Array)
#3 /home/daniel/Programming/app/vendor/laravel/framework/src/Illuminate/Database/Connection.php(624): Illuminate\Database\Connection->runQueryCallback('select * from `...', Array, Object(Closure))
#4 /home/daniel/Programming/app/vendor/laravel in /home/daniel/Programming/app/vendor/laravel/framework/src/Illuminate/Database/Connection.php on line 664
Laravel版本:5.5。*
PHP版本:7.1
背景故事:
我决定开发一个新的本地数据库安装,而不是总是依赖远程安装。然后我发现工匠不再工作了。
尝试:
每个工匠的命令我都可以得到,但是没有一个能够工作,因为即使php artisan --help
犯了上述错误......
我还尝试将repo克隆为一个新的开始,然后检查我正在处理的分支,并运行php artisan migrate
并出现相同的错误。
迁移:
我无法发布所有这些内容,但有一个迁移构建了丢失的表:
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreatePortalLinks extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('portal_viewer_user', function (Blueprint $table) {
$table->integer('viewer_user_id');
$table->integer('portal_id');
});
Schema::create('admin_user_portal', function (Blueprint $table) {
$table->integer('admin_user_id');
$table->integer('portal_id');
});
Schema::create('portals', function (Blueprint $table) {
$table->increments('id');
$table->string('identifier');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('viewer_user_portal');
Schema::dropIfExists('portal_admins');
Schema::dropIfExists('portals');
}
}
答案 0 :(得分:1)
错误原因:
错误是由在其构造函数中具有数据库查询的Laravel服务提供程序引起的。
事实证明 - 我不知道这一点 - Laravel服务提供商在运行工匠时得到实例化。
解决方案:
我在服务提供商中进行了一些验证,以阻止查询在artisan命令上发生,运行php artisan migrate:install
,php artisan migrate:fresh
和php artisan migrate --seed
由数据库填充所有必要的表格和记录。
答案 1 :(得分:0)
你正在尝试刷新。
你应该尝试php artisan migrate:新鲜
down命令不起作用,因为没有什么可以删除。
当你运行刷新命令时,laravel将首先尝试使用向下功能回滚所有内容。然后它将重建所有内容。在服务器上你从来没有遇到过问题,因为那些表就在那里。在这个新安装上,这个东西不能回滚。没有什么可以回滚的。