2

I'm experiencing a really strange issue where rails won't execute migrations on my machine. I'm using Rails 4.2.5, Ruby 2.3.1p112, and Postgres 9.5.3 on OS X 10.11.6.

The database creates/migrates and functions properly at Heroku and on another Mac with the same versions of everything.

If I import the database from Heroku or the other machine I get a pending migration error when running rails s, even when I'm on the same exact source version.

Running a db:schema tells me:

You have 23 pending migrations: 20160627035230 DeviseCreateUsers 20160627035442 CreatePages 20160627055031 AddHeroToPages 20160627061237 AddAdministratorToUser 20160627061943 AddNameToUser 20160628042547 CreateSchools 20160628042702 CreateLicenses 20160628042841 JoinUsersAndSchools 20160628043323 AddJoinCodeToSchools 20160630012028 AddExpiryToLicenses 20160630024743 CreatePurchases 20160630043846 AddOmniauthToUsers 20160704003626 CreateMyIndustries 20160704010403 CreateMyCareers 20160704013913 CreateMyQuestions 20160704074916 AlterMyQuestionsDrop 20160704075947 AlterMyQuestionsChange 20160705071702 CreateUserAttributes 20160710235339 CreateAccessabilities 20160711000000 AddToAccessabilities 20160711044815 CreateMedia 20160711045327 AddLocaleToMedium 20160814010549 CreateInvoices Run `rake db:migrate` to update your database then try again. 

Running the migration then tells me:

** Invoke db:migrate (first_time) ** Invoke environment (first_time) ** Execute environment ** Invoke db:load_config (first_time) ** Execute db:load_config ** Execute db:migrate ActiveRecord::SchemaMigration Load (0.3ms) SELECT "schema_migrations".* FROM "schema_migrations" ** Invoke db:_dump (first_time) ** Execute db:_dump ** Invoke db:schema:dump (first_time) ** Invoke environment ** Invoke db:load_config ** Execute db:schema:dump ActiveRecord::SchemaMigration Load (0.2ms) SELECT "schema_migrations".* FROM "schema_migrations" 

Listing tables in psql only shows the schema_migrations:

20:09 $ rails db psql (9.5.3) Type "help" for help. mytalents_development=# \dt List of relations Schema | Name | Type | Owner --------+-------------------+-------+---------------- public | schema_migrations | table | aidancornelius (1 row) mytalents_development=# 

I also seem to get strange errors with db:migrate:up

20:11 $ rake db:migrate:up rake aborted! ActiveRecord::UnknownMigrationVersionError: No migration with version number 0 /usr/local/lib/ruby/gems/2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:939:in `run' /usr/local/lib/ruby/gems/2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:834:in `run' /usr/local/lib/ruby/gems/2.3.0/gems/activerecord-4.2.5/lib/active_record/railties/databases.rake:82:in `block (3 levels) in <top (required)>' /usr/local/lib/ruby/gems/2.3.0/gems/rake-11.2.2/exe/rake:27:in `<top (required)>' Tasks: TOP => db:migrate:up (See full trace by running task with --trace) 

Does anyone have any insight about what might be going on here? Other projects in Rails 4 and Rails 5 work on this machine, but this one just won't.

Thanks in advance for any suggestions!

1
  • rake db:migrate:up needs a version number specified like in your case you can do rake db:migrate:up VERSION=20160627035230 Commented Aug 20, 2016 at 11:51

2 Answers 2

2

I bet this is an issue with Postgres Schemas. I had similar problem, but in my case migrations were working on my local machine and not on Heroku. It was caused by different settings to schema_search_path. On my local machine it was '"$user",public' but '"$user", public'" on Heroku and this additional space was breaking everything.

In your case you need to check what is your schema_search_path on your machine. Maybe you should set it to just "public" in database.yml file. You can check it with SHOW search_path query.

Sign up to request clarification or add additional context in comments.

1 Comment

That's exactly right. The old Rails code splits the result of show search_path on ,, which breaks with the new default value. The workaround is to place the following in the connection settings in database.yml: schema_search_path: '"$user",public'
1

The sequence of rails migration files (and migration process) is the most important part, so you can try to migrate the first migration file using:

rake db:migrate VERSION=20160627035230 

then use just db:migrate or db:migrate Version=20160814010549

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.