Mah*_*rli 9 php laravel laravel-migrations
首先我错误地回滚了2次迁移,然后我运行php artisan migrate命令,我收到以下错误:
[Illuminate\Database\QueryException]
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'exercise1.categories' doesn't exist (SQL: select * from
categories where parent_id = 0)
[PDOException]
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'exercise1.categories' doesn't exist
然后我停止了拉拉维尔.之后,当我运行php artisan serve启动Laravel 的命令时,我得到了同样的错误.以下是我已回滚的2次迁移:
1.
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');
}
}
Run Code Online (Sandbox Code Playgroud)
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');
}
}
Run Code Online (Sandbox Code Playgroud)
请帮我解决这个令人沮丧的问题.所有答案都非常感谢,提前感谢.
Mah*_*rli 20
如果您遇到此问题并且它不是由迁移文件引起的,那么很可能是因为2个可能的原因.
由于在启动laravel时首先加载ServiceProviders的引导函数和自动加载的自定义辅助函数,因此所有php artisan命令都将生成"基表或未查找视图"错误.
此时,您应该注释掉那些查询不存在的表并运行php artisan serve然后运行的查询php artisan migrate.然后取消注释这些行,保存它,一切都应该正常工作.
正如@devk建议的那样,最好检查laravel日志文件,它们指向问题发生的位置.它让我找到了解决方案.为此,请不要忘记打开调试模式.