Yes, I've read this.
This is what I'm getting in my production.log:
ActionView::TemplateError (undefined method `password' for #<User:0x2b0ddb58cdc0>) on line #11 of app/views/users/new.html.erb:
8: </p>
9: <p>
10: <%= f.label :password, "Password:" %><br />
11: <%= f.password_field :password %>
12: </p>
13: <p>
14: <%= f.label :password_confirmation, "Password again:" %><br />
When I try:
$ heroku rake db:reset RAILS_ENV=production
I get:
yeqynzfiku already exists
(in /disk1/home/slugs/109616_e6df6f2_8837/mnt)
Couldn't drop yeqynzfiku : #<ActiveRecord::StatementInvalid: PGError: ERROR: must be owner of database yeqynzfiku
: DROP DATABASE IF EXISTS "yeqynzfiku">
I don't know what this means. I've also tried
$ heroku rake db:reset
$ heroku rake db:migrate RAILS_ENV=production
$ heroku rake db:migrate
$ heroku rake gems:install (for what it's worth)
Everything works fine locally, both in development and production modes. I have a .gems file in my app, and when I first pushed to Heroku it seemed to install AuthLogic and Paperclip just fine.
Stumped. Thanks.
Sounds like you solved it, but with problems like this I find it handy do do a heroku restart.
For example, after running migrations with heroku rake db:migrate the app needs to be restarted before it will see those new columns.
Instead of db:reset try db:migrate VERSION=0 and db:migrate.
I think they have issues with reset because it tries to drop the db.
Also, you don't need to put RAILS_ENV=production it's the default AFAIK...
I had the same problem. I did a heroku restart and it worked perfectly.
Ah, had something to do with lots of things in the .gitignore file. Should have cleared it before pushing to Heroku.
Related
I am trying to reset my database.
It isn't working locally or in heroku.
I succuessfully ran each of these commands:
1. rake db:drop
2. rake db:create
3. rake db:migrate
The migrations took a while to succeed. I commented out the ones that were causing a problem and the whole job finishes migrating.
I then try to reset my database with:
4. rake db:reset
I get this error:
initialize_schema_migrations_table()
-> 0.0031s
rake aborted!
NoMethodError: undefined method `name=' for #<University:0x007fc288bdcca0>
/app/vendor/bundle/ruby/2.2.0/gems/activemodel-4.1.9/lib/active_model/attribute_methods.rb:435:in `method_missing'
I can't find anywhere in the code base that has a method called 'name' for university. I have run searches looking for university.name and name near university.
I have updated my gems and run bundle install.
What does this error message mean?
When I try:
rake db:reset --trace
I get:
** Execute db:abort_if_pending_migrations
rake aborted!
NoMethodError: undefined method name=' for #<University:0x007f9a1b24da30>
/Users/em/.rvm/gems/ruby-2.2.2/gems/activemodel-4.1.9/lib/active_model/attribute_methods.rb:435:inmethod_missing'
I have run all migrations and refreshed rake db:migrate
This is the error you get when you are trying to write to a variable that you haven't declared an attr_writer for.
class Foo
attr_reader :bar
def initialize
#bar = 1
end
end
> f = foo.new
=> #<Foo:0xa22ef0c #bar=1>
> f.bar
=> 1
> f.bar = 2
NoMethodError: undefined method `bar=' for #<Foo:0xa22ef0c #bar=1>
from (irb):23
from /usr/local/rvm/rubies/ruby-2.1.3/bin/irb:11:in `<main>'
It looks like you've got something in your seeds.rb file causing the error.
The reason you're seeing the issue when running rake db:reset but not when running those 3 individual steps is because rake db:reset doesn't run those 3 individual steps.
rake db:reset will run the following:
rake db:drop
rake db:setup
and subsequently, rake db:setup will run these:
rake db:create
rake db:schema:load
rake db:seed
If you only want to do the initial 3 steps (rake db:drop, rake db:create, rake db:migrate), you can run this instead:
rake db:migrate:reset
I was messing with my database, creating and deleting tables. I deleted few migration files after pushing them to heroku. Previously I created a table 'moms'. Later I wanted to rename it, so I deleted 'moms' and created new table 'minutes_of_meetings'. I did $rake db:migrate and everything was done successfully and my app is running perfectly on localhost.
After pushing it to heroku, when I did $heroku run rake db:migrate, it generated the following log:
ActiveRecord::SchemaMigration Load (0.7ms) SELECT "schema_migrations".* FROM "schema_migrations"
Migrating to DropMoms (20150823142852)
(0.6ms) BEGIN
== 20150823142852 DropMoms: migrating =========================================
-- drop_table(:moms)
(0.9ms) DROP TABLE "moms"
PG::UndefinedTable: ERROR: table "moms" does not exist
: DROP TABLE "moms"
(0.5ms) ROLLBACK
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
PG::UndefinedTable: ERROR: table "moms" does not exist
: DROP TABLE "moms"/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql/database_statements.rb:155:in `async_exec'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql/database_statements.rb:155:in `block in execute'
I created a new table 'moms' in heroku so that it can be deleted when migration runs. I did this:
$ heroku run Ruby console for rails-app-name >> ActiveRecord::Migration.create_table :moms
I also created a migration to create table 'moms'. But still the error persists.
EDIT:
This is my CreateMoms migration file:
class CreateMoms < ActiveRecord::Migration
def change
create_table :moms do |t|
t.string :name
t.timestamp null: false
end
end
end
When I run heroku run rake db:migrate:up
Running `rake db:migrate:up` attached to terminal... up, run.1729
rake aborted!
VERSION is required
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/railties/databases.rake:78:in `block (3 levels) in <top (required)>'
Tasks: TOP => db:migrate:up
(See full trace by running task with --trace)
WARNING: Toolbelt v3.41.3 update available.
On heroku run rake db:migrate:down
Running `rake db:migrate:down` attached to terminal... up, run.6389
rake aborted!
VERSION is required - To go down one migration, run db:rollback
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/railties/databases.rake:86:in `block (3 levels) in <top (required)>'
Tasks: TOP => db:migrate:down
(See full trace by running task with --trace)
WARNING: Toolbelt v3.41.3 update available.
Caution
rake db:schema:load will wipe away all of your data from the heroku database. Please make sure you have your data backup on heroku. If you already don't have backup of your heroku database, you can easily do so by using Heroku PGBackups
Looks like your schema is messed up. Just load the schema to the database using rake db:schema:load and then run the migration again:
heroku run rake db:schema:load
heroku run rake db:migrate
Within my ruby on rails application I have the seeds file, which contains data on the users such as:
User.create(:password => "jb", :password_confirmation => "jb", :role => 'admin', :first_name => "Joe", :last_name => "Bloggs", :house_no => "1", :street => "A Street", :town => "A Town", :postcode => "ABC1 2DE", :email => "anemail#anemailaddress.co.uk")
But when I run rake db:setup it removes all the users data that I have entered into the database through the application (which is fine and expected) but does not enter the users data from the seeds.
I'm not sure if this makes a difference but I recently did three consecutive scaffolds.
What am I doing wrong?
I think you are looking to do a rake db:seed. Here is a good explanation of the other db rake tasks Difference between rake db:migrate db:reset and db:schema:load
db:seed runs the db/seed.rb file
db:schema:load loads the schema into the current env's database
db:setup runs both db:schema:load and db:seed
I'm new to programming and rails so please forgive any big oversights. I recently deployed a rails app to heroku and switched all environments to postgres for my db. It is up on heroku working just fine with Postgres - ran rake db:drop db:migrate db:create db:seed all to populate my database with a rake task, tested the apps search forms, filters, data queries, etc. and it all worked well.
But I am now getting an error that says "comparison of ActiveSupport::SafeBuffer with nil failed" in the browser after firing up my local server and going to two of my views that have sorts - the browser is pointing me to a line in a view that has
<% #price_array.sort! {|x,y| x <=> y} %>
This is what I see in the server log:
Rendered skis/index.html.erb within layouts/application (212.9ms)
Completed 500 Internal Server Error in 280ms
ActionView::Template::Error (comparison of ActiveSupport::SafeBuffer with nil failed):
51: <% ski.inventories.each do |inventory| %>
52: <% a.push(number_to_currency(inventory.price)) %>
53: <% end %>
54: <% #lowest_price = a.sort { |x,y| x <=> y} %>
55: from <%= #lowest_price.first %>
56: </br>
57: </li>
app/views/skis/index.html.erb:54:in `sort'
app/views/skis/index.html.erb:54:in `block in_app_views_skis_index_html_erb___2303745325449705978_70146899313600'
app/views/skis/index.html.erb:32:in `each'
app/views/skis/index.html.erb:32:in `_app_views_skis_index_html_erb___2303745325449705978_70146899313600'
app/controllers/skis_controller.rb:32:in `index'
This may be related to the issue I am in running into - I cannot seem to drop my postgres database.
This is what I'm seeing in the terminal with postgres:
postgres=# \dbdrop postgres
List of tablespaces
Name | Owner | Location
------+-------+----------
(0 rows)
One other thing I did last night was update my .bash_profile per the instructions found here (http://stackoverflow.com/questions/6770649/repairing-postgresql-after-upgrading-to-osx-10-7-lion). This is what my .bash_profile looks like now:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function
PATH=/usr/local/bin:$PATH
Is there some configuration in postgres that I am missing that is causing this error? Any help or resources would be appreciated. Thanks.
you have nil values in your a array. Try :
a.compact.sort
compact removes all occurences of nil in your array.
In my app it was User model without 'name' field, when I added this field by migration. On my localhost my sign up form works fine, but on heroku I have this log:
ActionView::Template::Error (undefined method `name' for #<User:0x0000000518fb00>):
Rendered users/new.html.haml within layouts/application (3.1ms)
5: = f.input :name, required: 'true'
6: = f.input :email, required: 'true'
3: %h1 Sign up
4: = simple_form_for #user do |f|
7: = f.input :password
8: = f.input :password_confirmation, required: 'true'
What I've tried:
heroku run rake db:migrate
heroku run rake db:reset
but nothing helped.
you also have to restart heroku after migrating - you'd want to run
heroku run rake db:migrate
heroku restart
Make sure you have done git add .. Then git status to make sure that all the files have been committed. Then try the push again. Then migrate again.