Rails Many to Many SQLite3 error -


i created many-to-many relationship in rails, here's models , migrations

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 |t|       t.references :channel       t.references :package        t.timestamps     end     add_index :channels_packages, :channel_id     add_index :channels_packages, :package_id   end end 

then have multiple select, when try save error

sqlite3::constraintexception: constraint failed: insert "channels_packages" ("package_id", "channel_id") values (1, 1) 

i tried remove indexes migration didn't solve it, did else have problem?

btw i'm using rails 3.2.6 , sqlite3 1.3.6

i don't know if reason of problem, has_and_belongs_to_many association deprecated.

according rails guide:

the use of attributes on join table in has_and_belongs_to_many association deprecated. if require sort of complex behavior on table joins 2 models in many-to-many relationship, should use has_many :through association instead of has_and_belongs_to_many.

i know not adding attribute join table, try changing migration below, think default:

class createchannelpackagejointable < activerecord::migration   def change     create_table :channels_packages, :id => false |t|       t.integer :channel_id       t.integer :package_id        t.timestamps     end   end end 

Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -