mbleigh / seed-fu

Advanced seed data handling for Rails, combining the best practices of several methods together.
MIT License
1.23k stars 155 forks source link

Consider foreign key constraints #101

Open qsona opened 8 years ago

qsona commented 8 years ago

If table_a has table_b_id column, and the foreign key constraint exists, seed_fu tries to insert initial table_a data and fails because of the constraint.

As far as I know, seed_fu reads files in alphabetical order of filenames. So I can change the filenames into db/fixtures/01_table_b.rb and db/fixtures/02_table_a.rb to fix it, but I think it's better if we need not do it. Is there any solution? Thanks.

stuarthannig commented 7 years ago

Yes, foreign key constraint consideration would be nice. Working around it myself.

eliotsykes commented 6 years ago

Disabling referential integrity during seeding is a workaround for some situations, but note postgresql (and I'm assuming other dbs) will not validate the constraints afterward, so you can end up with orphaned foreign keys:

ActiveRecord::Base.connection.disable_referential_integrity do
  SeedFu.seed
end