houdini icon indicating copy to clipboard operation
houdini copied to clipboard

[BUG] ERROR: relation "active_storage_blobs" does not exist

Open kenspy opened this issue 3 years ago • 7 comments

Came across this issue while installing the v2.

Error

$ bin/setup

-- column_exists?(:active_storage_blobs, :service_name) 
rails aborted! 
StandardError: An error has occurred, this and all later migrations canceled: 
 
PG::UndefinedTable: ERROR:  relation "active_storage_blobs" does not exist 
LINE 8:  WHERE a.attrelid = '"active_storage_blobs"'::regclass 
 
/home/xxxxx/www/db/migrate/20210105192021_add_service_name_to_active_storage_blobs.active_storage.rb:4:in `up' 
 
Caused by: 
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR:  relation "active_storage_blobs" does not exist 
LINE 8:  WHERE a.attrelid = '"active_storage_blobs"'::regclass 

Fixed

rails active_storage:install

Your Environment

  • Ruby version: 2.7.2
  • Operating System and version: Ubuntu

kenspy avatar Mar 12 '21 03:03 kenspy

Hmm, despite active_storage successful installation, I am still unable to migrate, the error above still persist. Do I need to configure storage somewhere?

kenspy avatar Mar 12 '21 13:03 kenspy

@kenspy No, you shouldn't need to set anything up for storage, it just uses a directory /storage under the root.

Let me try to set this up in a separate VM and build from scratch and see if I can replicate this.

wwahammy avatar Mar 12 '21 20:03 wwahammy

@wwahammy Any luck reproducing the error?

kenspy avatar Mar 15 '21 11:03 kenspy

@kenspy, I looked at it on Friday and couldn't replicate the error. I'm not quite sure what's going on.

I think the best course of action would be to clear the database and start over. To do so run the following:

bin/rails db:drop db:create # deletes the db and recreates it
bin/setup # loads the db

Let me know if that doesn't work.

wwahammy avatar Mar 15 '21 16:03 wwahammy

I'm just trying to revive my Houdini development environment and hit this error PG::UndefinedTable: ERROR: relation "active_storage_blobs" does not exist. This occurs for me with a fresh database when running bin/setup - console output attached.

setup-log.txt

BenSturmfels avatar May 23 '23 06:05 BenSturmfels

@BenSturmfels thanks for that, I was able to recreate it!

The problem is due to a quirk about how bin/rails db:prepare works when called in bin/setup. db:prepare does one of two things:

  • if the database doesn't exist, it creates the database, loads the schema from scratch, which inherently includes all of the migrations, and runs the seed command (we don't really use that)
  • If the database does exist, it runs any migrations that haven't been run already.

The problem is when the database does exist but the schema hasn't been loaded yet, like in your case. In this situation, it tries to find what migrations need to be run, which in this case happens to be all of them. But it doesn't have any tables to run the migrations on so the entire thing fails.

As a work around, as long as all of the gems have been installed, run bin/rails db:schema:load which loads the schema. At that point, if you run bin/setup, everything should be fine.

db:prepare is a part of rails so I'm not going to modify it but this situation seems like something that should be better handled. I don't know that I have time to address this in general though. But please do document it in README.md and send a PR so others know the workaround.

wwahammy avatar May 25 '23 01:05 wwahammy

Thanks @wwahammy, this workaround got me going again. I'll look at documenting this.

BenSturmfels avatar Jun 19 '23 14:06 BenSturmfels