Note that there are some explanatory texts on larger screens.

plurals
  1. POModel scopes are breaking rake db:migrate - rails 3.2.3 postgres 9.1.3
    text
    copied!<p>I've come across a problem with running my migrations in a new rails app (3.2.3). We're using postrgres 9.1.3 and - pg (0.13.2) - </p> <p>When I run rake db:create, then rake db:migrate, I get -></p> <pre><code>1.9.3-p194 (master) rake db:migrate --trace ** Invoke db:migrate (first_time) ** Invoke environment (first_time) ** Execute environment rake aborted! PG::Error: ERROR: relation "roles" does not exist LINE 4: WHERE a.attrelid = '"roles"'::regclass ^ : SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull 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 &gt; 0 AND NOT a.attisdropped ORDER BY a.attnum </code></pre> <p>I get this even without any migrations defined, so I don't believe it's a problem with the migrations themselves. When I look at the stack trace, I see that scopes defined in my User model are being run - when I comment them out, the migrations run without a problem.</p> <pre><code>scope :team_leaders, where(role_id: Role.where(name: 'Team Leader').first.try(:id)) scope :area_leaders, where(role_id: Role.where(name: 'Area Leader').first.try(:id)) scope :nation_leaders, where(role_id: Role.where(name: 'Nation Leader').first.try(:id)) scope :employees, where(role_id: Role.where(name: 'Employee').first.try(:id)) </code></pre> <p>Is this a bug in rails, or am I doing something wrong? I'd really appreciate some help - we can remove the use of these scopes across the app, but this is something we'd like to avoid.</p> <p>Should I be putting these scopes inside some sort of conditional which is called when rails is loaded in the console or as a server but not during migrations?</p> <p>Thanks very much,</p> <p>Dan Sowter</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload