Is there any way to import contenttypes?

I want to work on a live Django CMS project locally. The live instance uses a MySQL database. The local installation uses the SQLite database. Usually for a regular django project, I would use dumpdata and omit auth.permission and contenttypes.
However Django CMS depends on the primary keys of the contenttypes to remain the same. Is there anyway to use dumpdata and loaddata to move the contenttypes table from one instance to the other?

I don’t see why not. However, you’ll also want to include all the permission and admin_log models as well. (Actually, if you follow all the transitive relationships, you may just want to replicate all tables starting with auth_ and django_.)

But trying to import the contenttypes always returns an integrity error. Is there any way to get past that?

Yea, that’s what I get for firing off an off-the-cuff answer. There is a little more to it than that.

What I managed to do:

  • Run dumpdata in the source database only for admin, auth, contenttypes
  • delete the existing database file. (Backing up whatever data desired)
  • Run migrate, in order, on:
    • contenttypes
    • auth
    • admin
  • Using dbshell, delete all data from:
    • auth_permission
    • django_migrations
    • django_content_type
  • Loaddata from the dumpdata above
  • Run migrate --fake on
    • admin
    • auth
    • contenttypes
  • Run migrate for the rest of the apps

This seemed to work - at least I don’t get any immediately-obvious errors from having done so, and I don’t think I missed any steps in transcribing it here.