首先,我错回滚2迁移,然后我跑php artisan migrate
命令,我得到了以下错误:无法启动Laravel,我得到“基表或视图未找到”错误
[Illuminate\Database\QueryException] SQLSTATE[42S02]: Base table or view not found: 1146 Table 'exercise1.categories' doesn't exist (SQL: select * from
categories
其中parent_id
= 0 ) [PDOException] SQLSTATE [42S02]:基表或视图未找到:1146表 'exercise1.categories' 不存在
然后我停止Laravel。之后,当我运行启动Laravel的命令php artisan serve
时,我得到相同的错误。 这里有两个迁徙我已经回滚:
class CreateCategoriesTable extends Migration
{
public function up()
{
Schema::create('categories',function (Blueprint $table){
$table->increments('id');
$table->string('name');
$table->text('parent_id');
$table->timestamps();
});
}
public function down()
{
Schema::dropIfExists('categories');
}
}
2.
class CreateArticlesTable extends Migration
{
public function up()
{
Schema::create('articles', function (Blueprint $table) {
$table->increments('id');
$table->string('title')->nullable(false);
$table->longText('article')->nullable(false);
$table->integer('user_id')->unsigned();
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->timestamps();
});
}
public function down()
{
Schema::dropIfExists('articles');
}
}
请帮我解决这个令人沮丧的问题。所有的答案都非常感谢,提前感谢。
做'composer dumpautoload'然后尝试再次迁移。 – aynber
如果您试图删除没有'dropIfExists()'的表,或者当您引用“类别”表的外键时,通常会出现此错误 - 您未在展示代码中执行此操作。你可能试图在其他迁移中引用'categories'表吗?也许你试图在后面的一些迁移中将外键添加到你的'parent_id'(一个猜测)? – devk
对于调试进一步检查app/storage/logs/laravel.log文件的结尾 - 哪个指向问题发生的地方 – devk