Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dumpdata with unmanaged models

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

like image 871
markwalker_ Avatar asked Aug 19 '13 12:08

markwalker_


1 Answers

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
like image 193
alecxe Avatar answered Nov 01 '22 14:11

alecxe