dumpscript skipping fields and I can't see why

3 views
Skip to first unread message

Caomhin

unread,
Apr 1, 2010, 6:01:02 AM4/1/10
to django-extensions
I'm trying to use dumpscript/runscript to migrate a database and seem
to be hitting a slightly awkward issue.

Essentially it seems the dumpscript is skipping a many-to-one field
when generating the script, which obviously gets noticed when I try a
runscript and get told the required field team_id is missing, and
indeed it is:

match_match_1 = Match()
match_match_1.date = datetime.datetime(2008, 8, 17, 10, 30)
match_match_1.home_or_away = u'A'
match_match_1.opponents = u'Hannikins Farm'
match_match_1.own_goals = 0L
match_match_1.goals_for = 0L
match_match_1.goals_against = 4L
match_match_1.competition = match_competition_5
match_match_1.save()

In the model team_id comes before date. The old database has 750 rows
which all have a team_id set, the new database has the required fields
in place waiting to be filled, but the data appears to be getting
skipped. I see a warning about if the relationship is new but it's
been there for a few years. I know 750 rows isn't vast but I'd still
rather not hand edit the thing if anyone has come across this before
or has ideas so... Any hints/tips/suggestions folks?

Will Hardy

unread,
Apr 6, 2010, 5:26:58 AM4/6/10
to django-e...@googlegroups.com
It could be that the team field (which I assume is a ForeignKey) is
set at the end of the script.

dumpscript does this because it wants to avoid setting id values and
use actual model instances, but if the team model instances haven't
been created yet, they can't be set at the beginning. They should
appear later in the script.

Let me know if this isn't the case.

Cheers,

Will

Caomhin

unread,
Apr 8, 2010, 12:58:39 PM4/8/10
to django-extensions
That made perfect sense so I didn't jump on it until today, and
remembered that's not the case.

Team is actually from a different models.py so that's imported at line
4.

team = models.ForeignKey(Team) <-- line 32

More a puzzler than anything else though, dumpscript has worked
flawlessly every other time so I've been assuming it's something weird
in my models.py - I just can't see anything out of the ordinary so
wondered.

Cheers,
Kevin

Will Hardy

unread,
Apr 8, 2010, 1:44:25 PM4/8/10
to django-e...@googlegroups.com
> Team is actually from a different models.py so that's imported at line
> 4.

Ah ok, maybe that's what's confusing dumpscript, I'll see if I can
create a failing test. What version of django are you on?

Cheers,

Will

Kevin Golding

unread,
Apr 8, 2010, 1:50:22 PM4/8/10
to django-e...@googlegroups.com
Aha! that not only makes sense but tallies up. Looking further into
the script I see another foreign key it skipped, which was using a
model from another app again.

This was all on Django 1.1.1 and Python 2.6.4.

Cheers,
Kevin

Will Hardy

unread,
Apr 8, 2010, 1:56:09 PM4/8/10
to django-e...@googlegroups.com
When you said another file, do you mean another app, or same app,
different file/module?

Kevin Golding

unread,
Apr 8, 2010, 2:39:28 PM4/8/10
to django-e...@googlegroups.com
Sorry, different app.

Unfortunately as team is pretty much the constant foreign key holding
together the other apps it stood out as the issue, but there are a
couple of other places where the apps inter-connect and it seems to
basically be happening in those cross-app foreign keys

Kevin

Reply all
Reply to author
Forward
0 new messages