Heroku部署Rails应用遇'users表不存在'错误求助
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 yourdb/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. Rungit statuslocally to confirm everything's staged, committed, and pushed.Run database migrations on Heroku
Open up your terminal and run these commands:- Log into your Heroku account:
heroku login - Navigate to your toy_app project directory, then run the migration command:
heroku run rails db:migrate
- Log into your Heroku account:
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

