About this article
When I execute "rails: db: migrate" in the flow of adding columns while creating my own application, "Directly inheriting from ActiveRecord :: Migration is not supported." Is displayed and an error occurs.
It was a rudimentary mistake, but I posted it as a memorandum!
[environment] ・ Ruby 2.6.5, Rails 6.0.0 ・ MacOS
rake aborted!
StandardError: An error has occurred, all later migrations canceled:
Directly inheriting from ActiveRecord::Migration is not supported. Please specify the Rails release the migration was written for:
Upon investigating, the cause seemed to be that the migration file did not correspond to the rails version. ..
Add the rails version to the end of the first line of the target migration file.
class AddAttachmentImageToPosts < ActiveRecord::Migration[6.0] #←[6.0]Add
def self.up
change_table :posts do |t|
t.attachment :image
end
end
def self.down
remove_attachment :posts, :image
end
end
After that, I tried the following again to solve the problem.
$ rails db:migarate
Finally
I think that there are many cases where you get an error when you implement it, and you do not get the results you want.
In such a case, let's calmly face the error sentence carefully!
Recommended Posts