Heroku not resetting database - ruby-on-rails

I am attempting to reset my database on heroku using this:
heroku pg:reset SHARED_DATABASE
and then run:
heroku run rake db:create db:migrate db:seed
But I am getting the following error:
Validation failed: Email has already been taken
I have noticed by going into the heroku rails console that the users are not being dropped and thus this validation has failed. What am I missing here?

Try this:
heroku pg:reset SHARED_DATABASE --confirm {the name of your app}
Substitute the name of your app where I have written {the name of your app}. For example, if your app is called my_great_app then you use:
heroku pg:reset SHARED_DATABASE --confirm my_great_app
To recreate the database with nothing in it:
heroku rake db:migrate
To populate the database with your seed data:
heroku rake db:seed
You can combine the last two into one action by executing this:
heroku rake db:setup

I've just been through this, here is what I did (step #3 was missing from the other answers which stalled me for a while):
heroku pg:info (to get the value of HEROKU_POSTGRESQL_HEROKUCOLOR_URL)
heroku pg:reset HEROKU_POSTGRESQL_HEROKUCOLOR_URL --confirm {app_name}
heroku run rake db:schema:load
heroku run rake db:migrate
heroku run rake db:seed
As per: Heroku rake db:migrate does not create tables (Rails 5)

Related

How reset Heroku PG DB via Heroku Scheduler?

I have demo ROR app in Heroku and I would like to reset PG DB everyday via Heroku Scheduler. I have some commands, but I don't know how I can use they in Heroku Scheduler. I just paste this, but it don't work for me.
commands:
heroku restart && heroku pg:reset DATABASE_URL --confirm APP_NAME_ON_HEROKU && heroku run rake db:migrate && heroku run rake db:seed
Could you please tell me, how I should to use this commands?
for me worked it:
rake db:schema:load DISABLE_DATABASE_ENVIRONMENT_CHECK=1 && rake db:seed
UPD:
the commands(heroku run rake db:migrate) that I performed early, working only from the Heroku CLI. For Heroku Scheduler we must use these commands without a keywords heroku run. rake db:reset don't work, disabled on the side Heroku. Also I couldn't use heroku pg:reset DATABASE_URL --confirm APP_NAME_ON_HEROKU.
useful links:
How to reset PG Database on Heroku?
Running Rake Commands
Here is the official documentation link
You can use the following command below.
heroku run rake db:schema:load DISABLE_DATABASE_ENVIRONMENT_CHECK=1 db:seed

Heroku run rake db:migrate

I did the following steps for deploying app and migrating my database:
git add -A
git commit -m "add changes"
git push heroku master
heroku run rake db:migrate
In console I see next:
Running `rake db:migrate` attached to terminal... up, run.9234
== 20150713191218 CreateMovies: migrating =================
-- create_table(:movies)
-> 0.0379s
== 20150713191218 CreateMovies: migrated (0.0381s) ============
heroku restart
But heroku run rake db:migrate does not work. When I run my app, my database is empty. I don't understand why. I don't see any errors.
And I'm sorry, that I repeat this question. I saw that people already asked about this problem, but no advice helped me.
try heroku run rake db:migrate RAILS_ENV=production
To populate your database automatically with rake task you need to use the command RAILS_ENV=production rake db:seed(this will populate your production database) and have a seed file in place. But I guess that was not really what you were looking for

why does rake db:migrate say my development database doesn't exist?

I'm typing in the terminal
rake db:migrate
Here's the error Im getting
ActiveRecord::NoDatabaseError: FATAL: database "db/development.sqlite3" does not exist
rake db:migrate doesn't create database, rather requires it exists.
rake db:create creates a database without loading database schema.
Remember you should run rake db:create before you can run rake db:migrate if you dropped database with rake db:drop.

Resetting database on heroku

Now I am trying to reset database on heroku but got stuck.
I know I should do "heroku pg:reset Database URL but I don't know exactly what the databese url is.
I did "heroku config". So I got some strings. And tried
heroku pg:reset postgres://ffsqtmlnxntfvl:ajqGTMGEmT7U1S6sVdi7-bb7Cm#ec2-107-20-245-109.compute-1.amazonaws.com:5432/dc2kahsue8hn20. Valid options are: DATABASE_URL, HEROKU_POSTGRESQL_AQUA_URL
My command,however,always returns this to me.
Unknown database: postgres://xxxxxxxxx:xxxxxxxxxxxxxxx#xxx-xxx-xx-xxx-xxx.compute-1.xxxxxxx.com:xxxx/xxxxxxxxxxxxxx. Valid options are: DATABASE_URL, HEROKU_POSTGRESQL_AQUA_URL
What should I do? Could you give me some advice?
You should use:
heroku pg:reset HEROKU_POSTGRESQL_AQUA
I know this question is old, but as I've just been through this, here is what I did:
heroku pg:reset HEROKU_POSTGRESQL_HEROKUCOLOR_URL --confirm {app_name}
heroku run rake db:schema:load
heroku run rake db:migrate
heroku run rake db:seed
As per: Heroku rake db:migrate does not create tables (Rails 5)

Running rake db:drop db:create db:migrate on Heroku Cedar stack

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
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.
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

Resources