I made what I now see as a mistake (better now than later, not as good as never) of running rake db:reset on my local dev env to try to solve a problem I was having with assets production compilation(RAILS_ENV=production bundle exec rake assets:precompile) referring to a PG ERROR summarized bellow.
PGError: ERROR: relation "schools" does not exist
LINE 4: WHERE a.attrelid = '"schools"'::regclass
The tables get created properly and seeding works with exception of active_admin. I use Active_Admin that did not seed properly. My emails mysteriously stopped being sent and the assets compilation for production still fails with the same error. I am not sure what I can post here to help you understand the issue but if someone could help me tackle one at a time that would be much appreciated. Here are my issues in list form.
active_admin not seeding (I tried running: rails generate active_admin:install but that started to break things further so I reverted this.
PG ERROR on assets precompile for production persists.
Email stopped being processed (not using DJ)
Env.
Rails 3.1
------UPDATE 00------
2 is Solved. db:reset dropped all my tables but only migrated and seeded my development database so I also had to:
run migrate and seed for production ( rake db:migrate RAILS_ENV="production", rake db:seed RAILS_ENV="production")
before compiling production assets(rake db:migrate RAILS_ENV="production")
I ended up splitting this question into 2 parts. The second part got better contribution and is where I found the solution for this as well.
Detailed solution here
Related
I am trying out an example from a book head first rails, i get to chapter 2 and i have issues following the instructions maybe because they used an older version of rails.
I am told to replace the development.sqlite3 file with the one provided on the site, and when i do so and try to run the run app again i get errors about pending migrations.
Note:
1. I already ran my migration using rake db:migrate
2. I downloaded the sqlite3 file and replaced the original file.
3. i started the server with rails s command.
4. I reload the page and then i get the error.
ActiveRecord::PendingMigrationError
Migrations are pending. To resolve this issue, run: bin/rails db:migrate RAILS_ENV=development
I have a feeling it has something to do with the schema.rb file? i dunno.
I'll really appreciate if someone can help me out here.
I have done my research, i've tried rake db:reset but to no avail. :(
see here:
[1]: http://headfirstlabs.com/books/hfrails you can scroll down to the code download section under chapter 2.
I'm cloning a RoR app from Github. After the clone I install my gems. Now at this point my question/problem arises. Some research I've done suggests I do a
rake db:create
followed by a
rake db:migrate
I've tried both of those steps but am still having trouble.
When I run
rails console
and do something like Plan.first it returns nil. And when I try to visit my application I get an ActiveRecord::RecordNotFound in PagesController#home error alluding to the fact that it can't find the plan id of 1.
Any help is much appreciated.
Thanks in advance!
You have an empty database with no data in it, if seeds are provided - rake db:seed will help, otherwise you'll have to create initial data youself (in rails console, or may be directly in db)
I've created a new Projects model for my application and everything works fine in development but in production on Heroku I receive a 500 error. The error is coming from my ProjectsController#create the error states:
2014-05-16T07:00:48.018827+00:00 app[web.1]:
2014-05-16T07:00:48.018832+00:00 app[web.1]: ActiveRecord::StatementInvalid (PG:
:UndefinedColumn: ERROR: column "taggings_count" does not exist
2014-05-16T07:00:48.018834+00:00 app[web.1]: LINE 1: UPDATE "tags" SET "taggings
_count" = COALESCE("taggings_coun...
2014-05-16T07:00:48.018835+00:00 app[web.1]:
Which is almost the exact same error as the one in this issue that I found after some searching: https://github.com/KatanaCode/blogit/issues/57. This person said they solved it by pulling these new migrations from acts_as_taggable https://github.com/mbleigh/acts-as-taggable-on/tree/master/db/migrate
I'm fairly certain that I have the same problem but I'm new to rails and not sure what he means by he pulled those migrations. Do I just update my acts_as_taggable gem and push to heroku? Can someone point me in the right direction? Thanks in advance.
Since you're new (welcome btw!!!), here's your error:
ActiveRecord::StatementInvalid (PG::UndefinedColumn: ERROR: column "taggings_count" does not exist
This is a standard error, basically meaning you don't have that column in your db
Your acts_as_taggable is looking for the taggings_count column in your production db, and it's not there. A simple fix is to use the rake db:migrate method in your production environment (Heroku):
$ heroku run rake db:migrate RAILS_ENV=production
This wil run the migrate method on your heroku instance, which should populate the db for you. This is exclusive of any bugs/errors acts-as-taggable may have
Error
In regards to the specifics of your error, the link you gave basically says the newest version of acts-as-taggable has introduced several migrations, which your app will not have included
The way to fix they recommended was to take the migration files as defined here, and put them into their db/migrate directory -- allowing you to populate your db correctly
If you need help with this (after trying rake db:migrate), comment & I'll give you some more info
This problem seems to only occur when the model attribute is called 'tags', it causing some sort of conflict but only in production. Dropping the column and creating a new one with a different name worked for me.
You can just rollback and migrate again:
heroku run rake db:rollback STEP=5
heroku run rake db:migrate
STEP=5 because acts_as_taggable creates 5 migrations
I have a Rails app which I have recently pushed up to Heroku. When I try to migrate the database with:
heroku run rake db:migrate
I am getting the rake aborted! message and complains about a table that doesn't exist.
Locally, when I run the migrate command there are no issues so why is Heroku different?
I did experience this issue the last time I migrated on Heroku too - I ended up using:
heroku rake db:schema:load
to overcome the problem but I really want to get to the root of the problem so it stops happening.
Any suggestions?
EDIT: I know which migration file is at fault but is it safe to remove a file from the migrations folder?
I pushed an update to my Rails app production server, and in the update there was a new database migration. I ran rake db:migrate and got the common error seen here. I ran the rake again in bundle exec bash and it was successful. But after restarting my apache server, I'm now getting the 500 Error page. This update worked fine on my localhost, and was mostly this update to the db with supporting changes in the according view and controller/routing.
I don't even know why this error appeared this time, as I have pushed db updates successfully before using only rake. Nonetheless, the rake was successful. The 500 error page only shows on pages that require that specific new ActiveRecord. Any ideas on how to debug?
EDIT: My problem was an extremely simple one. I merely forgot to include the environment with the rake:
bundle exec rake db:migrate RAILS_ENV=production
Unfortunately, it took quite a while to narrow that down, as I couldn't use IRB to check the db entries until I followed these steps.
Did you run rake db:migrate on your server? Also be sure to set the RAILS_ENV flag so your production database is updated:
rake db:migrate RAILS_ENV=production