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

Heroku部署Rails应用遇'users表不存在'错误求助

Fixing the PG::UndefinedTable Error on Heroku for Your Rails Toy App

Hey there! Let's get that 500 error sorted out. The issue here is pretty straightforward: your local database has the users table because you ran migrations locally, but Heroku's PostgreSQL database hasn't executed those migration scripts yet—so it doesn't know the users table exists.

Here's how to fix it step by step:

  • First, double-check your migration files are pushed to BitBucket
    Make sure all the files in your db/migrate/ directory are committed and pushed to your BitBucket repo. Heroku pulls code directly from your repo, so if the migration files aren't there, it can't create the tables. Run git status locally to confirm everything's staged, committed, and pushed.

  • Run database migrations on Heroku
    Open up your terminal and run these commands:

    1. Log into your Heroku account:
      heroku login
    2. Navigate to your toy_app project directory, then run the migration command:
      heroku run rails db:migrate

This command tells Heroku to execute all your pending database migrations, which will create the users table (and any other tables your app needs) in its PostgreSQL database.

Once the migration finishes, try visiting https://salty-wave-17330.herokuapp.com/users again—it should load without the 500 error!

A quick reminder for future deployments: every time you add new migration files and push to BitBucket, you'll need to run heroku run rails db:migrate to keep Heroku's database in sync with your code.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.13 08:25:55