RailsApps / rails-devise-pundit

Rails 5.0 starter app with Devise for authentication and Pundit for authorization.
http://railsapps.github.io/rails-devise-pundit/
483 stars 156 forks source link

relation "roles" does not exist #5

Closed stereodenis closed 10 years ago

stereodenis commented 10 years ago
init  applying migrations and seeding the database
         run    bundle exec rake db:migrate from "."
         run    bundle exec rake db:seed from "."
ROLES
rake aborted!
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR:  relation "roles" does not exist
LINE 5:                WHERE a.attrelid = '"roles"'::regclass
                                          ^
:               SELECT a.attname, format_type(a.atttypid, a.atttypmod),
                     pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
                FROM pg_attribute a LEFT JOIN pg_attrdef d
                  ON a.attrelid = d.adrelid AND a.attnum = d.adnum
               WHERE a.attrelid = '"roles"'::regclass
                 AND a.attnum > 0 AND NOT a.attisdropped
               ORDER BY a.attnum
/Users/stereodenis/work/stereopark/rails-devise-pundit/db/seeds.rb:12:in 'block in <top (required)>'
/Users/stereodenis/work/stereopark/rails-devise-pundit/db/seeds.rb:11:in 'each'
/Users/stereodenis/work/stereopark/rails-devise-pundit/db/seeds.rb:11:in '<top (required)>'
Tasks: TOP => db:seed
(See full trace by running task with --trace)
DanielKehoe commented 10 years ago

Are you using Rails 4.1.0.rc2? Does the migration work if you use SQLite?

DanielKehoe commented 10 years ago

Closing issue due to lack of response.

binyamindavid commented 10 years ago

I tried this too and it didn't work. So i thought it would be better to create roles like this.

  # have zero as the default role. Since enum auto does it for me
   t.integer   :role, default: 0, null: false

 #then my  user model looks like this 
 enum role: [:user, :banned, :admin]

Not sure if it's bad but it seems to work.

jackson-sandland commented 10 years ago

The vagueness...location?

DanielKehoe commented 10 years ago

Do you have an issue to report?

binyamindavid commented 10 years ago

@jackson-sandland not sure i understand your comment.

jackson-sandland commented 10 years ago

@DanielKehoe I'm having this exact same issue...I'm using Devise and Rails 4 - the sign up works beautifully locally, but not on heroku. These are the logs => 2014-07-08T22:45:47.074079+00:00 app[web.1]: Processing by Devise::RegistrationsController#new as HTML 2014-07-08T22:45:47.087034+00:00 app[web.1]: F, [2014-07-08T22:45:47.086932 #5] FATAL -- : 2014-07-08T22:45:47.087038+00:00 app[web.1]: ActiveRecord::StatementInvalid (PG::UndefinedTable: ERROR: relation "admin" does not exist 2014-07-08T22:45:47.087039+00:00 app[web.1]: LINE 5: WHERE a.attrelid = '"admin"'::regclass 2014-07-08T22:45:47.087043+00:00 app[web.1]: : SELECT a.attname, format_type(a.atttypid, a.atttypmod), 2014-07-08T22:45:47.087041+00:00 app[web.1]: ^ 2014-07-08T22:45:47.087045+00:00 app[web.1]: pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod 2014-07-08T22:45:47.087046+00:00 app[web.1]: FROM pg_attribute a LEFT JOIN pg_attrdef d 2014-07-08T22:45:47.087065+00:00 app[web.1]: vendor/bundle/ruby/2.1.0/gems/activerecord-4.0.3/lib/active_record/connection_adapters/abstract_adapter.rb:430:in log' 2014-07-08T22:45:47.087048+00:00 app[web.1]: ON a.attrelid = d.adrelid AND a.attnum = d.adnum 2014-07-08T22:45:47.087056+00:00 app[web.1]: vendor/bundle/ruby/2.1.0/gems/activerecord-4.0.3/lib/active_record/connection_adapters/postgresql_adapter.rb:774:inasync_exec' 2014-07-08T22:45:47.087049+00:00 app[web.1]: WHERE a.attrelid = '"admin"'::regclass 2014-07-08T22:45:47.087063+00:00 app[web.1]: vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.3/lib/active_support/notifications/instrumenter.rb:20:in instrument' 2014-07-08T22:45:47.087082+00:00 app[web.1]: vendor/bundle/ruby/2.1.0/gems/activerecord-4.0.3/lib/active_record/connection_adapters/schema_cache.rb:56:inyield' 2014-07-08T22:45:47.087051+00:00 app[web.1]: AND a.attnum > 0 AND NOT a.attisdropped 2014-07-08T22:45:47.087058+00:00 app[web.1]: vendor/bundle/ruby/2.1.0/gems/activerecord-4.0.3/lib/ac

jackson-sandland commented 10 years ago

@DanielKehoe I have reset the database on Heroku. I have checked the schema. Admin is a table that exists, and the routes are defined in routes.rb.

DanielKehoe commented 10 years ago

I've just deployed the app to Heroku and did not encounter any problem. Try:

$ heroku pg:reset DATABASE
$ heroku run rake db:migrate
$ heroku run rake db:seed
$ heroku restart

Maybe you forgot to run $ heroku run rake db:migrate?

Also check your Gemfile to make sure you've specified:

source 'https://rubygems.org'
ruby '2.1.2'
gem 'rails', '4.1.4'
DanielKehoe commented 10 years ago

Also you say that "Admin is a table that exists." But the application has no table named 'admin'. The table is 'users'.

jackson-sandland commented 10 years ago

@DanielKehoe Thank you! I ran the migration and then checked the results...I must have deleted a migration so when I rake:db migrated the app on heroku the Admin table was not being created. I made a new migration, and I have solved that issue! However, now I am getting a 500 error in the Heroku logs because I added a :username attribute to the Devise form, but it is producing the following: 2014-07-08T23:55:19.663959+00:00 app[web.1]: Rendered devise/registrations/new.html.erb within layouts/application (2.0ms) 2014-07-08T23:55:19.667137+00:00 app[web.1]: ActionView::Template::Error (undefined method `username' for #): 2014-07-08T23:55:19.667139+00:00 app[web.1]: 4: <%= devise_error_messages! %> 2014-07-08T23:55:19.667142+00:00 app[web.1]: 6:

<%= f.label :username %>
2014-07-08T23:55:19.667144+00:00 app[web.1]: 7: <%= f.text_field :username, autofocus: true %>
2014-07-08T23:55:19.664099+00:00 app[web.1]: Completed 500 Internal Server Error in 4ms 2014-07-08T23:55:19.667133+00:00 app[web.1]: F, [2014-07-08T23:55:19.667038 #8] FATAL -- : 2014-07-08T23:55:19.667141+00:00 app[web.1]: 5:

DanielKehoe commented 10 years ago

I can help you when you encounter errors with the example application. I can't help with errors introduced by your custom code.

My Rails and Devise Tutorial has a chapter on adding additional attributes to the Devise views. It might be helpful. You can also ask on Stack Overflow.

jackson-sandland commented 10 years ago

Thank you Daniel. It's working!

On Tue, Jul 8, 2014 at 5:03 PM, Daniel Kehoe notifications@github.com wrote:

I can help you when you encounter errors with the example application. I can't help with errors introduced by your custom code.

My Rails and Devise Tutorial http://railsapps.github.io/rails-devise/ has a chapter on adding additional attributes to the Devise views. It might be helpful. You can also ask on Stack Overflow.

— Reply to this email directly or view it on GitHub https://github.com/RailsApps/rails-devise-pundit/issues/5#issuecomment-48414900 .