houdini
houdini copied to clipboard
[BUG] ERROR: relation "active_storage_blobs" does not exist
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
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 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 Any luck reproducing the error?
@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.
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.
@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.
Thanks @wwahammy, this workaround got me going again. I'll look at documenting this.