You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Laravel新环境执行migrate:refresh --seed报错:migrations表不存在

数据库迁移报错:Table 'svadbenilokali.migrations' doesn't exist

在全新应用/服务器环境执行命令php artisan migrate:refresh --seed时,触发如下错误:

Illuminate\Database\QueryException 

  SQLSTATE[42S02]: Base table or view not found: 1146 Table 'svadbenilokali.migrations' doesn't exist (Connection: mysql, SQL: select `migration` from `migrations` order by `batch` asc, `migration` asc)

  at vendor/laravel/framework/src/Illuminate/Database/Connection.php:822
    818▕                     $this->getName(), $query, $this->prepareBindings($bindings), $e
    819▕                 );
    820▕             }
    821▕ 
  ➜ 822▕             throw new QueryException(
    823▕                 $this->getName(), $query, $this->prepareBindings($bindings), $e
    824▕             );
    825▕         }
    826▕     }

  i   A table was not found: You might have forgotten to run your database migrations. 
      https://laravel.com/docs/master/migrations#running-migrations

      +37 vendor frames 

  38  artisan:37
      Illuminate\Foundation\Console\Kernel::handle()

已尝试分开执行迁移与填充操作、移除路由中的auth配置,均未解决问题;本地环境迁移和填充功能正常。


解决方向

  • 核对.env文件中的数据库配置(DB_HOST、DB_PORT、DB_DATABASE、DB_USERNAME、DB_PASSWORD),确认与服务器数据库信息完全匹配,重点检查数据库名称svadbenilokali是否正确存在
  • 手动登录服务器数据库,若目标数据库svadbenilokali未创建,执行SQL命令CREATE DATABASE svadbenilokali;创建
  • 先执行基础迁移命令php artisan migrate(不带refresh参数),因migrate:refresh会先尝试回滚迁移,但此时migrations表尚未存在,回滚操作会触发报错;待migrations表创建完成后,再使用migrate:refresh --seed
  • 检查服务器数据库用户权限,确保该用户拥有创建表、修改表的完整权限,避免因权限不足导致migrations表无法生成
  • 清除Laravel配置缓存:执行php artisan config:clear,确保服务器读取最新的.env配置,而非缓存的旧配置

内容的提问来源于stack exchange,提问作者M A

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.05 08:57:12