Rails 4.0.1 on Heroku, can't create database

ぃ、小莉子 提交于 2019-11-30 01:13:08

I would first try

heroku restart

heroku rake db:migrate

If that doesn't work, then try.

heroku pg:reset DATABASE_URL   #Literally type in heroku pg:reset DATABASE_URL

heroku rake db:migrate
user2043725

I should've read the stack trace more closely. My factories.rb was creating user objects as attributes for other factories. Wrapping them in a block fixed it:

FactoryGirl screws up rake db:migrate process

Run

heroku pg:reset DATABASE_URL

and you are done.

Eduardo Veras

Jason's answer might fix your problem, but I wanted to expand on why you got the error and how to fix it.

  1. You can't run "rake db:setup" on Heroku, because it will try to create a database, and your database already exists on Heroku

  2. In your database.yml, you should read the database url from the environment variable like: production: url: <%= ENV["DATABASE_URL"] %>

  3. I think you are getting the 2nd error because you have some version error in your migrations, runing them from the begining should fix it : rake db:migrate VERSION=0

To drop and recreate database

  1. Login to heroku in terminal
  2. cd into your app
  3. Run

heroku pg:reset DATABASE

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!