Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failing on production/heroku: WHERE a.attrelid = '"schools"'::regclass

I added a table to my local env called schools and it works fine in dev. In fact it even works fine in staging (heroku) but fails big time in production and rake db:migrate throws the error bellow.

I cannot even precompile assest (with RAILS_ENV=production), access any part of my application including the rails console in production(heroku). Everything is throwing the error bellow. I have lost several hours on this but do not feel any closer to figuring it our. (Note: I have '"..."' on the reference to the table_name which I think is part of the problem)

I went from rails 3.1.0 to 3.1.3 so that might have something to do with it.

PGError: ERROR:  relation "schools" does not exist

LINE 4:              WHERE a.attrelid = '"schools"'::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 = '"schools"'::regclass
               AND a.attnum > 0 AND NOT a.attisdropped
             ORDER BY a.attnum

I am as lost as can be on this. I read several other questions on this topic here but no solution at sight. Thank you for your help. Any insight is greatly appreciated.

UPDATE------------------------------------------------------

I just created a brand new app on heroku and ran rake db:migrate and got the same error.

UPDATE 2

I cloned the app from heroku and "schools" is in the schema.

create_table "schools", :force => true do |t|
  ...
  ...
end

UPDATE 3

Tried reverting back to rails 3.1.0 but that did not help.

UPDATE 4

Still working on this. Have not heard from heroku support yet.

UPDATE 5

Heroku support was able to check that 'schools' is not a table in the DB but I still cannot access the console and app still down.

like image 971
Yuri Avatar asked Jan 09 '12 06:01

Yuri


3 Answers

Heroku Support helped me solve this even though it was not necessarily heroku's platform related issue as we found out.

I was having a chicken-and-egg issue, where the migration wouldn't run because the rails bootstrap was trying to talk to the table and the table was not created because migration could not run. ActiveAdmin was initializing when rails boots, and was trying to look up schools. Thank you everyone that helped.

like image 98
Yuri Avatar answered Nov 14 '22 10:11

Yuri


I've solved it by commenting

#ActiveAdmin.routes(self)

in routes before migration. After completing of migration i've just uncomments this line and everything work fine.

like image 29
Vasiliy Shakhunov Avatar answered Nov 14 '22 10:11

Vasiliy Shakhunov


No, the quoting should not be a problem. While the double quotes are not needed in this case, they are not wrong, either:

SELECT '"schools"'::regclass

I would consider that PostgreSQL is right and the relation schools does no exist - in your database and in a schema that is part of your search_path.

If you can connect to your database, you could run this query to diagnose your problem:

SELECT n.nspname AS schema_name
      ,c.relname AS table_name
      ,c.relhastriggers
      ,c.reltuples
FROM   pg_catalog.pg_class c
LEFT   JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE  c.relname ~~* '%schools%'
AND    c.relkind = 'r'
AND    nspname <> 'pg_catalog';

Finds every table where the name contains the string schools. Similar to the psql meta-command:

\dt *schools*

Make sure you are connected with the same user to the same database where you have the problem.

like image 1
Erwin Brandstetter Avatar answered Nov 14 '22 11:11

Erwin Brandstetter