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 at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to