Hello, I was wondering if anyone knows a good way to handle restoring a
backup taken with a m2m intermediary model.

I'm trying to upgrade from my sqlite database to a real database and would
like to keep the data that was created thus far.

Basically the models look like this:

class Message(models.Model):
    subject = models.CharField(max_length=64)
    ...
    recipients = models.ManyToManyField(User, through='SentRecord',
blank=True)

class SentRecord(models.Model):
    message = models.ForeignKey(Message)
    recipient = models.ForeignKey(User)
    sent_at = models.DateTimeField(auto_now=True)

So I've tried both dumpdata/loaddata and dumpscript/runscript.  The former
basically quietly ignores the records but everything else is OK -- but no
Messages or SentRecords.

So I've tried two approaches -- first problem was regarding the fact that
SentRecord and Message refer to one another and so one has to be created
first. dumpscript picked SentRecord to do first -- totally sensible.  But
It can't comply with the above model because the .message foreign key will
create a column that enforces NOT NULL.

OK fine, I changed the above model to allow null on message, since it
basically does this sequence:

1. create sent messages, with no message pk
2. create messages
3. then it *should* fill in the sent messages .message pk... but instead it
blows up because because it generates stuff like this:

app_message_1.recipient.add( importer.locate_object(User, 'id', 1, ...

Which is a big no no because of the through record it's using wrong
manager.  It should be getting the sent records already created and setting
the .message pk on those instead of trying to add Users directly to the
message, as though it were a regular m2m.


I'm just wondering if anyone knows if this is a fixed issue and I'm just
'holding it wrong'... otherwise I'll be faced with some stark choices, fix
django-extensions to get my way... or do some ugly sed/awk to patch it up.

Thank you!

=D

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAGq7KhoAkw57YzmEZReouD7Fr9f0fX7mG-bhdGgSRu3Oc07xiA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to