heroku rake db:migrate didn't work - ruby-on-rails

I've run a migration adding active column to users using heroku rake db:migrate.
and succesfully. but when I run the application the "active" column/attributes is not defined.
I already try to migrate:down and run migrate again for that version.. but it's still not worked.

did you add :active to the list of accessible attributes?
attr_accessible :active
failing that, sometimes you need to run heroku rake db:restart
and just finally, if it's still not working, run heroku logs and you will probably find something

Try this, it will run both the up and the down which will help you better analyze the situation. Also, there may be a problem in your migrations, if you post the code I should be able to asset further.
rake db:migrate:redo

Try to restart you application or drop database, if it doesnt contain valuable information.

Related

RAILS: Editing old migration files to solve ActiveRecord::IrreversibleMigration

I have a few old migration files that contain a change method. When executing rake db:migrate VERSION=0 they give an ActiveRecord::IrreversibleMigration, I can change the migration to have and up and down method, which solves the error on my local machine, but is this a good idea or will it cause problems? For example when deploying to production?
What is the right way of solving this issue?
Thanks.
Rule of thumb is: Changing old migrations is ok, when either:
It has never been run anywhere else (e.g. you are the only developer and it hasn't been deployed yet)
It has already been run in production
I personally like to have all migrations work from any point on my local machine so that when something goes wrong I can just execute:
rake db:drop && rake db:create && rake db:migrate
The only problem that I see is, when your changing of the migration would significantly change the schema. Then you'd end up with a different schema in production and development. This might cause problems with debugging and bug fixing.

Heroku - undo rake db:reset

I was having issues deploying my Heroku Rails app - and came across another SO post that suggested using:
heroku run rake db:reset
Which I ran without thinking, and of course my database was dropped and setup... and I no longer have any data on my heroku app.
Is there an easy way to get my database info back? I tried running
heroku run rake db:rollback
but haven't had any luck yet.
Anyone know of any easy solution to this? I kind of need this data, and most definitely cannot lose it! Thanks for any help you can offer!
rake db:reset
Can not be undone unless you have a database backup. If you found a database backup use the following to restore your database.
psql dbname < infile
Tips:
1. rake db:rollback does not get your database back. Instead, it rollbacks the last migration in your schema_migrations table.
2. Always create database backups for your production applications.
3. Read this answer it may come in handy.

How do I undo bundle exec rake db:setup?

How do I undo bundle exec rake db:setup?
I ran it in the wrong rails app. I ran it in the blogger when I should have ran it in the blogger_advanced app.
You can do rake db:drop
.
It will drop all tables (thats any tables created by setup, any migrations run by setup and any seeds created by setup)
You may use rake db:rollback and it'll rollback migrations one by one, but if yours apps have same named models (User for example) it'll be lost. So you need to dump this tables first and recreate them later using database administrator tool.
And also it'll broke your schema_migrations table and you'll need to refill it by hands from your migration file names.
So if there is not much useful info, it's better to use #Alexphys approach.

Heroku: How to push seeds.rb to existing rails app?

I store all my app's data in seeds.rb locally. However, after I pushing everything to Heroku, the app works well, but without any data. I do not want to re-input the mass data again, so does anyone have any ways to help me?
If you push the app to heroku, you can seed the database with the following command.
heroku run rake db:seed
If you have changed migrations then first you need to do is run migration
heroku run rake db:migrate
then
heroku run rake db:seed
If you don't have any data in database the I would suggest following is, But caution it will remove all current data from heroku database.
heroku run rake db:setup
Hope this helps you
you have to be sure no migration is pending
if no pending
just do
heroku run rake db:migrate
and it will word perfectly
I'll just add, because I haven't seen it yet.
heroku run rails db:seed
Will accomplish the same task.

Rails - how to solve this issue of an orphaned migration?

After rake db:migrate:rollback STEP=1, rake db:migrate:reset, rake db:migrate:setup, rake db:migrate:up VERSION=XXXXXXXXX I get the following entry:
Status Migration ID Migration Name
------------------------------------------------------
up 0 *********NO FILE**********
up 20120209023430 Create tasks
How can I get rid of the orphaned entry? I have encountered this problem a few times after raking the db similar to above. Could somebody please explain what exactly causes this.
Thx in advance.
Shahram
You could use rake db:migrate:reset db:seed. It's a little less verbose and will completely wipe your database, re-run all migrations, and then seed your database from the db/seeds.rb file.
I've just released this gem that can solve this issue for good.
The idea of that gem is simple. It keeps all migrated migrations inside tmp folder so that Git ignores them. It's just only your local story. These files are needed to roll back the "unknown" migrations being in another branch. Now, whenever you have an inconsistent DB schema due to running migrations in some other branch just run rails db:migrate inside the current branch and it will fix the issue automatically. The gem does all this magic automatically for you.

Resources