10

I'm developing a Django (1.9) Rest backend and AngularJS frontend with Cross-site referencing. While attempting to execute a ./manage.py dumpdata command, it throws the following exception:

$ python manage.py dumpdata -o dev/dumpdata.json
CommandError: Unable to serialize database: relation 
"corsheaders_corsmodel" does not exist
LINE 1: SELECT COUNT(*) AS "__count" FROM "corsheaders_corsmodel"

Any idea how to handle?

Myk Willis
  • 12,306
  • 4
  • 45
  • 62
user3897818
  • 101
  • 3

2 Answers2

24

I had this same problem, and resolved it by invoking python manage.py makemigrations specifically for the corsheaders app:

$ python manage.py makemigrations corsheaders
$ python manage.py migrate

I think what happened in my case was that, after an upgrade from Django 1.8 to 1.9, the initial migration was never applied when I updated my DB.

I tracked it down by noticing that the corsheaders app was not listed in the Apply all migrations output of python manage.py migrate:

$ python manage.py migrate
Operations to perform:
  Apply all migrations: sessions, admin, xyz, auth, contenttypes
Running migrations:
  No migrations to apply.

Yet running a manual migration for corsheaders actually creates the initial migration:

$ python manage.py makemigrations corsheaders
Migrations for 'corsheaders':
  0001_initial.py:
    - Create model CorsModel

After having done that, a migrate does show corsheaders in the output, and successfully applies the migration as expected:

$ python manage.py migrate
Operations to perform:
  Apply all migrations: corsheaders, sessions, admin, xyz, auth, contenttypes
Running migrations:
  Rendering model states... DONE
  Applying corsheaders.0001_initial... OK
Myk Willis
  • 12,306
  • 4
  • 45
  • 62
2

If corsheaders_corsmodel table does not exist, then there's no data to dump. So you can just run:

$python manage.py dumpdata --exclude=corsheaders 

I had the same problem and I solve it this way.

Pastor
  • 318
  • 1
  • 11