I am attempting to run a rake:db migrate on a postgres database for my rails application. rake:db drop (the db already existed I am fixing a bug that requires I recreate the db) runs fine rake:db create runs fine but when I run rake:db migrate I get the following error
ERROR --: PG::InvalidSchemaName: ERROR: no schema has been selected to create in.
My database.yml file looks fine (it was working so I'm not sure what happened?)
development:
adapter: postgressql
encoding: utf8
username: [myusername]
password: [mypassword]
host: [myhost]
port: 5432
database: myapp_dev
schema_search_path: "myapp_dev"
pool: 5
timeout: 5000
Any idea what is going on?
Rails does not automatically create schemas AFAIK, if you stick to the public schema that fact can be ignored and things just work.
To use a different schema you will have to include a migration to do so, a raw SQL one like this will do:
class CreateMyAppSchema < ActiveRecord::Migration
def up
execute "CREATE SCHEMA myapp_dev;"
end
def down
execute "DROP SCHEMA myapp_dev;"
end
end
In addition to the schema in the schema search path existing, the user needs to have the USAGE privilege on the myapp_dev schema
GRANT USAGE on schema myapp_dev to the_user;
For some reason there was no "myapp_dev" schema in my database, when I created it using the PGAdmin tool it fixed the issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With