Django 1.9 with CORS dumping data: "corsheaders_corsmodel" does not exist
Asked Answered
L

2

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?

Lott answered 18/12, 2015 at 5:5 Comment(3)
Do you have the current version of corsheaders installed?Bidet
django-cors-headers==1.1.0Lott
Could you please select a correct answer to this question? It seems @myk-willis has the right one.Kommunarsk
F
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
Finnie answered 31/1, 2016 at 20:30 Comment(0)
C
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.

Cabochon answered 25/11, 2016 at 21:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.