Open stanko-tomic opened 7 years ago
I had the same problem when I was putting [5.0] after the migration name so I tried with [4.2] instead and it worked!
Just remove the following line from *_act_as_tatggable_on_migration.acts_as_taggable_on_engine.rb
:
add_index :taggings, :tag_id
Cause:
add_index :taggings, :tag_id
already add the index.
Thanks @RaccoonFive ,I have the same problem, use [4.2] instead works!
Added a unless index_exists?(:taggings, :tag_id)
postifx to add_index :taggings, :tag_id
line 23 on *_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb
to fix.
Using Rails 5.1.3, after generating migrations with rails acts_as_taggable_on_engine:install:migrations
, I then tried to migrate them with bundle exec rails db:drop db:create db:migrate
but it gave me error
Caused by:
StandardError: Directly inheriting from ActiveRecord::Migration is not supported. Please specify the Rails release the migration was written for:
class ActsAsTaggableOnMigration < ActiveRecord::Migration[4.2]
So I fixed that error by just appending the missing [5.1]
to each migration (i.e. class ActsAsTaggableOnMigration < ActiveRecord::Migration[5.1]
)
Then when I ran bundle exec rails db:drop db:create db:migrate
again it gave me error:
== 20171104224110 ActsAsTaggableOnMigration: migrating ========================
-- create_table(:tags)
-> 0.0049s
-- create_table(:taggings)
-> 0.0191s
-- add_index(:taggings, :tag_id)
rails aborted!
StandardError: An error has occurred, this and all later migrations canceled:
Index name 'index_taggings_on_tag_id' on table 'taggings' already exists
I fixed this by using advice from @stoplion by modifying db/migrate/20171104224110_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb by
appending unless index_exists?(:taggings, :tag_id)
to the line add_index :taggings, :tag_id
so it became add_index :taggings, :tag_id unless index_exists?(:taggings, :tag_id)
Caused by: ArgumentError: Index name 'index_taggings_on_taggable_id_and_taggable_type_and_context' on table 'taggings' does not exist
On *_add_missing_unique_indices.acts_as_taggable_on_engine.rb file
Change this line
remove_index :taggings, [:taggable_id, :taggable_type, :context]
to
if index_exists? :taggings, [:taggable_id, :taggable_type, :context]
remove_index :taggings, [:taggable_id, :taggable_type, :context]
end
You can reference my gist for migration errors and configuration. https://gist.github.com/rokumatsumoto/e7225334767c68c1859e097442f647a1
Thanks @RaccoonFive ,I have the same problem, use [4.2] instead works!
thanks
When i try running rake db:migrate it outputs this `C:\Sites\novosti>rails db:migrate 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 ActsAsTaggableOnMigration < ActiveRecord::Migration[4.2] C:/Sites/novosti/db/migrate/20170708123900_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb:2:in'
StandardError: Directly inheriting from ActiveRecord::Migration is not supported. Please specify the Rails release the migration was written for:
<top (required)>' bin/rails:4:in
require' bin/rails:4:in `class ActsAsTaggableOnMigration < ActiveRecord::Migration[4.2] C:/Sites/novosti/db/migrate/20170708123900_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb:2:in
<top (required)>' bin/rails:4:in
require' bin/rails:4:in<main>' Tasks: TOP => db:migrate (See full trace by running task with --trace)
I fixed it buy putting
[5.0]
on the end of the generatedacts_as_taggable_on_migration.acts_as_taggable_on_engine
But then i got this error
`C:\Sites\novosti>rake db:migrate == 20170708144217 ActsAsTaggableOnMigration: migrating ======================== -- adapter_name() -> 0.0000s -- adapter_name() -> 0.0000s -- create_table(:tags, {:id=>:integer}) -> 0.0029s -- adapter_name() -> 0.0000s -- adapter_name() -> 0.0000s -- create_table(:taggings, {:id=>:integer}) -> 0.0032s -- add_index(:taggings, :tag_id) rake aborted! StandardError: An error has occurred, this and all later migrations canceled:
Index name 'index_taggings_on_tag_id' on table 'taggings' already exists C:/Sites/novosti/db/migrate/20170708144217_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb:23:in
up' ArgumentError: Index name 'index_taggings_on_tag_id' on table 'taggings' already exists C:/Sites/novosti/db/migrate/20170708144217_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb:23:in
up' Tasks: TOP => db:migrate (See full trace by running task with --trace)`