Rails Many to Many SQLite3 error Rails Many to Many SQLite3 error sqlite sqlite

Rails Many to Many SQLite3 error


I think gabrielhilal's answer is not quite correct: use of extra attributes in the join table is deprecated, thus you need to remove the timestamp in your migration, then it should work just fine with the has_and_belongs_to_many wich itself is not deprecated.

If you do need additional attributes in your join table, though, has_many :through is the way to go.

There is also another question with good answers on this topic:Rails migration for has_and_belongs_to_many join table


I don't know if it is the reason of your problem, but the has_and_belongs_to_many association is deprecated.

According to the Rails Guide:

The use of extra attributes on the join table in a has_and_belongs_to_many association is deprecated. If you require this sort of complex behavior on the table that joins two models in a many-to-many relationship, you should use a has_many :through association instead of has_and_belongs_to_many.

I know that you are not adding any extra attribute to the join table, but try changing your migration to the below, which I think is the default:

class CreateChannelPackageJoinTable < ActiveRecord::Migration  def change    create_table :channels_packages, :id => false do |t|      t.integer :channel_id      t.integer :package_id      t.timestamps    end  endend