Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

Unable to call rake task twice, with postgresql #28

Open
urzur opened this issue Aug 26, 2013 · 1 comment
Open

Unable to call rake task twice, with postgresql #28

urzur opened this issue Aug 26, 2013 · 1 comment

Comments

@urzur
Copy link

urzur commented Aug 26, 2013

Hello,

I have a rake task that looks like this:

namespace :db do
desc "Erase and fill database"
task :populate => :environment do

[A,B].each(&:delete_all)

A.populate 15 do |a|
  a.title = Populator.words(5..8)

    B.populate 3 do |b|
      b.a_id = a.id
      b.title = Populator.words(5..8)
    end#B

  end#A

end#task

end#namespace

Using sqlite3, whenever I call the rake task multiple times, everything works.
Using postgresql, first time works like a charm (asuming I just migrated the database) but the second+ times it fails. When looking at
A.all.to_a (using Rails 4)
B.all.to_a

I have data for both models but each record in b has an invalid id for a_id and associations are lost (ie. I cannot do a.bs)

obvious here a, b are places holders.

This seems to happen with postgresql and not sqlite3. Getting the same error on heroku (uses postresql) and in local machine

@GantMan
Copy link

GantMan commented Mar 17, 2015

I'm having the same issue.

Just doing a rake db:drop and rake db:setup puts me back at index 1, so it works. But I have to kill ALL tables with that drop.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants