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.
I came across this issue when running tests.
Simply reset the database for
test
environment: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.
No, the quoting should not be a problem. While the double quotes are not needed in this case, they are not wrong, either:
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 yoursearch_path
.If you can connect to your database, you could run this query to diagnose your problem:
Finds every table where the name contains the string
schools
. Similar to thepsql
meta-command:Make sure you are connected with the same user to the same database where you have the problem.
I've solved it by commenting
in routes before migration. After completing of migration i've just uncomments this line and everything work fine.