レールで多対多の関係を作成しました。これが私のモデルと移行です
class Channel < ActiveRecord::Base
has_and_belongs_to_many :packages
validates_presence_of :name
end
class Package < ActiveRecord::Base
has_and_belongs_to_many :channels
validates_presence_of :name
end
class CreateChannelsPackages < ActiveRecord::Migration
def change
create_table :channels_packages, :id => false do |t|
t.references :channel
t.references :package
t.timestamps
end
add_index :channels_packages, :channel_id
add_index :channels_packages, :package_id
end
end
次に、複数選択がありますが、保存しようとするとこのエラーが発生します
SQLite3::ConstraintException: constraint failed: INSERT INTO "channels_packages" ("package_id", "channel_id") VALUES (1, 1)
移行からインデックスを削除しようとしましたが、解決しませんでした。他の誰かがこの問題を抱えていましたか?
ところで、私はRails 3.2.6とsqlite3 1.3.6を使用しています