Running rake db:drop db:create db:migrate on Heroku Cedar stack
Asked Answered
K

2

34

When I try to run:

heroku run rake db:drop db:create db:migrate

I get the error:

Running rake db:drop attached to terminal... up, run.5
Couldn't drop adsfsadfas : #<ActiveRecord::StatementInvalid: PGError: ERROR:  must be owner of database adsfsadfas
: DROP DATABASE IF EXISTS "adsfsadfas">

I am on the Heroku Cedar stack. Am I allowed to drop databases on Heroku?

Thanks!

John

Kyanite answered 17/11, 2011 at 5:11 Comment(1)
Here is an up to date answer: https://mcmap.net/q/451387/-how-to-get-shared-database-url-in-herokuTjirebon
O
52

The rake db:reset task is not supported. Heroku apps do not have permission to drop and create databases. Use the heroku pg:reset command instead.

Outrider answered 17/11, 2011 at 5:13 Comment(5)
yeah, you need to type heroku pg:reset SHARED_DATABASE then input your app name at the prompt when askedDancer
this has now changed to heroku pg:reset DATABASE_URL --confirm nameofapp - ymmvDancer
Note also with the (now deprecated) Heroku gem, heroku pg:reset DATABASE_URL will also delete your schema, despite heroku help pg docs indicating "Delete all data in the database". Though, in the OP's case that's what is wanted (rake db:drop).Toulouse
Joshua Schmid pointed out that you may need to also run: heroku run rake db:schema:loadCampbellite
heroku pg:reset then heroku run rake db:migrate (and optionally db:fixtures:load as that was for my staging environment)Truda
K
13

Directly destructive commands (drop and create) are not permitted on heroku. But if you're ok with loosing all the data, you can reset the database with pg:reset.

heroku pg:reset DATABASE_URL

Every other change should be done with db:migrate. This assures consistency of the database state.


If your migrations don't run through the full stack anymore you can use db:schema:load. This loads the schema directly from schema.rb. But be aware that this can also be destructive if create_table uses the parameters force: true or force: :cascade.

heroku run rake db:schema:load
Kimberykimble answered 5/6, 2015 at 8:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.