Dumpdata with unmanaged models
Asked Answered
C

1

11

I'm trying to dump my database (sqlite3) to a json file for a fixture, but I have an unmanaged model which is causing a no such table error (obviously!) so how do you dumpdata with these kind of models in the db?

Model:

from django.db import models


class Backup(models.Model):
    """
    This class is lazily recycled between various forms that ask the user to
    provide a path to some data.
    """

    dbloc = models.CharField(
        max_length = 255
    )

    class Meta:
        app_label = 'myApp'
        db_table = 'backup'
        managed = False

Error:

CommandError: Unable to serialize database: no such table: backup

Collarbone answered 19/8, 2013 at 12:21 Comment(0)
I
15

Just exclude this model using --exclude option. Quote from docs:

The --exclude option may be provided to prevent specific applications or models (specified as in the form of appname.ModelName) from being dumped. If you specify a model name to dumpdata, the dumped output will be restricted to that model, rather than the entire application. You can also mix application names and model names.

./manage.py dumpdata myApp --exclude=myApp.Backup
Intermediate answered 19/8, 2013 at 12:28 Comment(1)
Do you know why django does not automatically exclude unmanaged models from dumpdata?Higginbotham

© 2022 - 2024 — McMap. All rights reserved.