I might be wrong but the bags_packages table is a many-to-many
relationship. This relationship is expressed in Rails by
has_and_belongs_to_many. You should probably take a look at what you
have set as primary keys. Have them all set as primary. You should
also look at how you are creating rows. From what it looks like you are
sending 1, 1, 2 twice (or more). Check your logs and see.