Unable to run migration scripts

13 views
Skip to first unread message

Joe Tseng

unread,
Jul 8, 2018, 11:37:01 AM7/8/18
to Ruby on Rails: Talk
I've been creating an app using Ruby on Rails on Windows for almost two years and I've had it. This weekend I started migrating my dev environment over to Ubuntu because it can run some tools/services not available in Windows.

I tried to run a migration and I got this error msg:

    $ bundle exec rake db:migrate
    
    rake aborted!
    StandardError: An error has occurred, this and all later migrations canceled:
    
    Directly inheriting from ActiveRecord::Migration is not supported. Please specify the Rails release the migration was written for:
    
      class AddAttachmentImportCsvFileToTabClientProjectCommunities < ActiveRecord::Migration[4.2]
    /home/joe/.rvm/gems/ruby-2.3.3/gems/activerecord-5.1.6/lib/active_record/migration.rb:525:in `inherited'
    /home/joe/workspace/asb_base/db/migrate/20170829235908_add_attachment_import_csv_file_to_tab_client_project_communities.rb:1:in `<top (required)>'

I thought maybe it was because the version of RoR I had on Ubuntu (Ruby 2.5.1/Rails 5.2.0) was different than that on Windows (v2.3.3/v5.1.4). I explicitly locked my RoR versions to use what I had in Windows and then ran the migration - still the same error msg. Has anyone else encountered this before?

Frederick Cheung

unread,
Jul 8, 2018, 11:48:38 AM7/8/18
to Ruby on Rails: Talk
On Sunday, July 8, 2018 at 5:37:01 PM UTC+2, Joe Tseng wrote:
>

> I thought maybe it was because the version of RoR I had on Ubuntu (Ruby 2.5.1/Rails 5.2.0) was different than that on Windows (v2.3.3/v5.1.4). I explicitly locked my RoR versions to use what I had in Windows and then ran the migration - still the same error msg. Has anyone else encountered this before?

In the olden days migrations inherited straight from ActiveRecord::Migration. As the error message says, you now need to inherit from a version specific class (ActiveRecord::Migration[4.2], ActiveRecord::Migration[5.1]), depending on which version of Rails you were using when you wrote the migration. This makes it much easier for the rails team to introduce new behaviour to migrations in the future without breaking existing migrations. If it’s a really old migration (ie it is already “included” in the schema.rb or database dumps you use) you might find it easier just to delete the old migrations rather than updating them all.

As an aside you are running rails 5.1.6, ie neither of the versions you mention, so perhaps there is something about that you haven’t understood. The version your app uses should be specified in your Gemfile, (and then with the fully resolved dependencies in Gemfile.lock) so moving to a new machine shouldn’t produce problems based on gem versions - bundler will install the same version of all the gems.

Fred
Reply all
Reply to author
Forward
0 new messages