Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.

#1 June 21, 2010 13:49:51

d.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Force ContentType id


I had to clean my application database from old models without losing
data.
So, I copied my tables to another db, dropped them, run syncdb and
copied data back.
But the app stopped working, because some tables used GenericRelations
and still pointed to the old ContentType; so, I had to change that id
manually.

Is there a way to force the id of a model in django_content_type
table?
Or, is there a way to run a syncdb to apply changes without losing
data?

Thanks.

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 June 22, 2010 01:06:50

Russell K.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Force ContentType id


On Mon, Jun 21, 2010 at 8:49 PM, donato.gr <donato...@gmail.com> wrote:
> I had to clean my application database from old models without losing
> data.
> So, I copied my tables to another db, dropped them, run syncdb and
> copied data back.
> But the app stopped working, because some tables used GenericRelations
> and still pointed to the old ContentType; so, I had to change that id
> manually.
>
> Is there a way to force the id of a model in django_content_type
> table?

No - the content type handling is completely automated and
non-optional. There's also no way to force a given model to have a
specific content type id.

However, you may be able to correct the problem using fixtures. Either
dump the contenttypes from your old database; if you don't have the
old database anymore, then dump the contenttypes of the new database
into a fixture, and manually modify the primary keys.

If you're using a database without referential integrity, you may be
able to simply dump the current contents of the contenttypes table and
load your corrected fixture. If you're using Postgres, this approach
will cacade delete any foreign keys on ContentType, so you'll need to
dump the entire database *except* for the contenttype table, load your
fixture, then run sycndb to get the remaining tables. syncdb won't
create new contenttypes if a record already exists, so it will use the
contenttypes from your fixture.

> Or, is there a way to run a syncdb to apply changes without losing
> data?

I'm not sure what you're asking here -- syncdb is *never* destructive.
Running syncdb should never result in data loss.

Yours,
Russ Magee %-)

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#3 June 22, 2010 09:58:05

d.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Force ContentType id


Thank you,
your explanation was very clear and useful.

> > Or, is there a way to run a syncdb to apply changes without losing
> > data?

Our software product is under development and sometimes we have the
need to change a model definition (e.g. rename a field or change its
definition):
is there a way to make syncdb understand that the model has changed
and then make all necessary 'ALTER TABLE' queries?
I found some topics about tools such as 'django evolution' but I was
wondering if Django itself provides a simpler way to make simple
alterations...


Thanks,
Donato

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#4 June 22, 2010 10:01:48

Simon B.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Force ContentType id


On 22 June 2010 09:58, donato.gr <donato...@gmail.com> wrote:
> I found some topics about tools such as 'django evolution' but I was
> wondering if Django itself provides a simpler way to make simple
> alterations...

It's not built in to Django, but it sounds like you want South -
<http://south.aeracode.org/>.

--
Cheers,
Simon B.

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#5 June 22, 2010 12:34:49

d.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Force ContentType id


Thanks,
I'll have a look

On 22 Giu, 11:01, Simon Brunning <si...@brunningonline.net> wrote:
> On 22 June 2010 09:58, donato.gr <donato...@gmail.com> wrote:
>
> > I found some topics about tools such as 'django evolution' but I was
> > wondering if Django itself provides a simpler way to make simple
> > alterations...
>
> It's not built in to Django, but it sounds like you want South -
> <http://south.aeracode.org/>.
>
> --
> Cheers,
> Simon B.

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

Board footer

Moderator control

Enjoy the 18th of October
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support