Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 513
user3897818 Avatar asked Dec 18 '15 05:12

user3897818


2 Answers

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
like image 55
Myk Willis Avatar answered Nov 20 '22 06:11

Myk Willis


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.

like image 30
Pastor Avatar answered Nov 20 '22 06:11

Pastor