Okay. I'm stumped.
I have a command that loads data from a CSV file and creates some models (geodjango models if that matters), like so:
# How many we will store at a time batch_size = 250 # parse the file and create the model instances (without saving) names =  locations =  for row in file_reader: name = row names.append(name) location_obj = Location(name=row, longlat=row) locations.append(location_obj) # Get a list of names that are already in the database current_names = Location.objects.filter( name__in=names).values_list('name', flat=True) for loc_objs in izip(*[locations] * batch_size): loc_objs = [l for l in loc_objs if l.name not in current_names] try: Location.objects.bulk_create(loc_objs) except IntegrityError as e: pass
There's a unique index on name. With the above I get an integrity error for EVERY SINGLE DAMN ROW.
I checked and none of these names exist in the database, it still threw the error.
I deleted every row through shell, it still threw the error.
I made absolutely sure it was deleted and did it through psql. Yep, still threw it.
I reindexed the index through psql. ERROR
I reindexed the table through psql. I HATE MY LIFE RIGHT NOW.
Short of sacrificing a goat the next full moon and hoping a benevolent ,albeit bloodthirsty, deity smiles down upon my sacrifice, I have no idea what to do next. Set the database on fire and order a new one? Have my code exorcised?
If anyone can help with this, or recommend a good, remote place where I can go and live as a hermit after giving up on technology, I would be eternally grateful.
EDIT: I should point out. I have checked the file itself for duplicates and it doesn't have any. So they aren't coming from within a single batch (if that's possible)