Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Directly inheriting from ActiveRecord::Migration is not supported. Please specify the Rails release the migration was written for: #2667

Open
Souravgoswami opened this issue Sep 19, 2020 · 3 comments

Comments

@Souravgoswami
Copy link

Deprecation notice

Paperclip is currently undergoing deprecation in favor of ActiveStorage. Maintainers of this repository will no longer be tending to new issues. We're leaving the issues page open so Paperclip users can still see & search through old issues, and continue existing discussions if they wish.

I know this is deprecated, but I am doing a course where I have to use this gem instead of ActiveStorage or Carrierwave.

The problem is, in Rails 6.0, whenever I run rails db:{drop,create,migrate} I get:

Dropped database 'db/development.sqlite3'
Dropped database 'db/test.sqlite3'
Created database 'db/development.sqlite3'
Created database 'db/test.sqlite3'
== 20200914221802 CreatePictures: migrating ===================================
-- create_table(:pictures)
   -> 0.0048s
== 20200914221802 CreatePictures: migrated (0.0050s) ==========================

== 20200916062631 DeviseCreateUsers: migrating ================================
-- create_table(:users)
   -> 0.0053s
-- add_index(:users, :email, {:unique=>true})
   -> 0.0019s
-- add_index(:users, :reset_password_token, {:unique=>true})
   -> 0.0040s
== 20200916062631 DeviseCreateUsers: migrated (0.0150s) =======================

== 20200916063812 AddUserIdToPics: migrating ==================================
-- add_column(:pictures, :user_id, :integer)
   -> 0.0048s
== 20200916063812 AddUserIdToPics: migrated (0.0049s) =========================

== 20200916064238 AddUsernameToUsers: migrating ===============================
-- add_column(:users, :username, :string)
   -> 0.0060s
== 20200916064238 AddUsernameToUsers: migrated (0.0062s) ======================

rails 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 AddAttachmentImageToPics < ActiveRecord::Migration[4.2]
/home/sourav/railsProjects/InstagramApp/db/migrate/20200919075557_add_attachment_image_to_pics.rb:1:in `<main>'
/home/sourav/railsProjects/InstagramApp/bin/rails:9:in `<top (required)>'
/home/sourav/railsProjects/InstagramApp/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'

Caused by:
StandardError: Directly inheriting from ActiveRecord::Migration is not supported. Please specify the Rails release the migration was written for:

  class AddAttachmentImageToPics < ActiveRecord::Migration[4.2]
/home/sourav/railsProjects/InstagramApp/db/migrate/20200919075557_add_attachment_image_to_pics.rb:1:in `<main>'
/home/sourav/railsProjects/InstagramApp/bin/rails:9:in `<top (required)>'
/home/sourav/railsProjects/InstagramApp/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)

The issue can be fixed simply by modifying the migration file, and add [6.0] beside ActiveRecord::Migration, for me it's something like this:

class AddAttachmentImageToPics < ActiveRecord::Migration[6.0]
  def self.up
    change_table :pictures do |t|
      t.attachment :image
    end
  end

  def self.down
    remove_attachment :pics, :image
  end
end

And then run:

rails db:environment:set RAILS_ENV=development db:{drop,create,migrate}

This is a temporary fix that has to be followed every time I create migration...

@Smailancer
Copy link

Smailancer commented Feb 5, 2022

after doing those changes , I got this message

C:\Users\Admin\Desktop\Ruby\instagrameme>rails db:environment:set RAILS_ENV=development db:migrate
== 20220205102326 AddAttachmentImageToPics: migrating =========================
-- change_table(:pics)
rails aborted!
StandardError: An error has occurred, this and all later migrations canceled:

wrong number of arguments (given 3, expected 2)
C:/Users/Admin/Desktop/Ruby/instagrameme/db/migrate/20220205102326_add_attachment_image_to_pics.rb:4:in block in up' C:/Users/Admin/Desktop/Ruby/instagrameme/db/migrate/20220205102326_add_attachment_image_to_pics.rb:3:in up'

Caused by:
ArgumentError: wrong number of arguments (given 3, expected 2)
C:/Users/Admin/Desktop/Ruby/instagrameme/db/migrate/20220205102326_add_attachment_image_to_pics.rb:4:in block in up' C:/Users/Admin/Desktop/Ruby/instagrameme/db/migrate/20220205102326_add_attachment_image_to_pics.rb:3:in up'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)

@pjgomes85
Copy link

Did you solved this issue? I have the exact same problem with Rails[7.0]

@Jyothsna-Siripuram
Copy link

Did you solved this issue? I have the exact same problem with Rails[7.0]

NO. I am also getting the same issue

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants