4

When I run rake db:migrate I get the following error:

ActiveRecord::StatementInvalid: PG::InvalidSchemaName: ERROR:  no schema has been selected to create in
: CREATE TABLE "schema_migrations" ("version" character varying NOT NULL) 

PG::InvalidSchemaName: ERROR:  no schema has been selected to create in

Tasks: TOP => db:migrate
(See full trace by running
ActiveRecord::StatementInvalid: PG::InvalidSchemaName: ERROR:  no schema has been selected to create in
: CREATE TABLE "schema_migrations" ("version" character varying NOT NULL) 

PG::InvalidSchemaName: ERROR:  no schema has been selected to create in

Tasks: TOP => db:migrate
(See full trace by running task with --trace) task with --trace)

I have no idea how to fix it and would welcome any ideas.

I am running rails 4.

This error came about because I was originally using a MySQL database (worked fine), but then switched to pgSQL to allow for easy uploading to heroku. and now it's neither working on the local host nor on heroku.

Lee
  • 29,398
  • 28
  • 117
  • 170
BenKoshy
  • 33,477
  • 14
  • 111
  • 80
  • 2
    This might help you http://dba.stackexchange.com/questions/106057/error-no-schema-has-been-selected-to-create-in – Shefalee Chaudhary Oct 19 '16 at 05:23
  • 2
    also check this solution http://stackoverflow.com/a/14286370/4318953 – Shefalee Chaudhary Oct 19 '16 at 05:24
  • I came across the problem while upgrading gitlab in a test environment. The above answers were essentially correct. It's always a good policy on PG databases to bludgeon the permissions on the `public` schema to prevent anyone from using them, which is what I did. But then I didn't restore them properly so the gitlab user could use them. Once I transferred ownership of the schema (via the stackoverflow link), it worked. – Otheus Feb 27 '18 at 14:42

1 Answers1

3

This error occurs when the schema mentioned in the search path doesn't exist. You might have configured schema search path in database configuration. You can remove schema search path from configuration. If you want to keep the schema search path, create the schema first.