【问题标题】:Base table or view not found during migration迁移期间未找到基表或视图
【发布时间】:2026-01-19 04:50:01
【问题描述】:

我正在宅基地运行退出的 laravel 项目。运行 php artisan migrate 时出现错误。

这里是完整的错误。

在 Connection.php 第 664 行:

  SQLSTATE[42S02]: Base table or view not found: 1146 Table 'forum.chanel' doesn't exist (SQL: select * from `chanel`)  


In Connection.php line 326:

  SQLSTATE[42S02]: Base table or view not found: 1146 Table 'forum.chanel' doesn't exist 

这是我的香奈儿表

public function up()
    {
        Schema::create('chanels', function (Blueprint $table) {
            $table->increments('id');
            $table->string('title');
            $table->string('slug');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('chanels');
    }

为什么会出现此错误以及如何解决此错误?

运行 composer update 时出现错误

【问题讨论】:

  • 数据库名称是论坛
  • 检查迁移的名称和顺序
  • 一切都像我运行项目之前一样

标签: laravel artisan-migrate


【解决方案1】:

首先需要在命令下面重新迁移类型

php artisan migrate:fresh

然后使用以下命令运行带有迁移文件的新模型

php artisan make:model chanel -m

使用此命令自动创建迁移文件和模型文件 在 {your app}\database\migrations

中编辑迁移文件位置
  $table->string('title');
  $table->string('slug');

将上面一行添加到公共函数 up(){ // 代码 }

现在在代码下方运行迁移类型

php artisan migrate

这对你有帮助

【讨论】:

  • 没有 artsan 命令工作。我的数据库是新鲜的。没有表存在
【解决方案2】:

您的模型名称和表名称似乎不同步, 在此之前从数据库中删除所有表可能是迁移表中的问题或迁移安排运行composer dumpa 然后

尝试通过指定 $table 名称来更新模型,

class Chanel extends Model{
    public $table = "chanels";

【讨论】:

  • 能否请您从数据库中删除所有表然后再次迁移,当您在任何表数据存在之前播种时也是如此。
【解决方案3】:

您需要检查您的migration 表以查看过去是否已经运行过此迁移,开发人员在运行迁移后更改代码是很常见的。

或者,在迁移运行之前,您可能有一些偶数/拦截正在运行查询 select * from chanel,这导致迁移失败。

【讨论】:

  • 你是对的,但我找不到问题和解决方案
  • 如果它不在生产中,您需要回滚所有迁移并再次迁移。