1

I have an application in Django 1.6.5. I have a model where I removed one field, I added another field, and the third upgraded. And when we now turn to the model in the admin panel, I get the message:

ProgrammingError at /admin/app/subscription/
column app_subscription.enabled does not exist

The command python manage.py syncdb does not work.

Zulu
  • 8,765
  • 9
  • 49
  • 56
mark
  • 653
  • 1
  • 10
  • 23
  • @Scironic I get an error: `python manage.py migrate app The app 'app' does not appear to use migrations.` – mark Mar 30 '15 at 10:54
  • Did you check if there are no references to ```enabled``` field in all files of your project? (especially in ```admin.py```'s). – Ihor Pomaranskyy Mar 30 '15 at 10:55
  • @IgorPomaranskiy no references – mark Mar 30 '15 at 10:55
  • 2
    @mark: migrations are not automagically created. – bruno desthuilliers Mar 30 '15 at 10:56
  • Also in strings? (for example, in lists of field names) – Ihor Pomaranskyy Mar 30 '15 at 10:57
  • @brunodesthuilliers so I must do `python manage.py makemigrations app` then `python manage.py migrate app` then `python manage.py syncdb`? – mark Mar 30 '15 at 10:58
  • @mark: you're using django 1.6, which doesn't have migrations support built in (please refer to the documentation for *your* version of Django, `makemigration` is for django >= 1.7). You do have a `migrate` command so I assume you have `South` (http://south.aeracode.org/) installed, so your best bet is to read `South`'s documentation, cf my answer. – bruno desthuilliers Mar 30 '15 at 11:09

2 Answers2

2

Django (hopefully) doesn't modify your database schema if you don't explicitely ask for it. The syncdb command works perfectly, but (as documented) it will only create tables that don't yet exists (and are not marked as being managed externally in your models).

So you have mostly three options here:

  1. manually drop your table and re-run syncdb. This mean you will loose all our data, so it's hardly a "solution"
  2. manually alter your database schema. You won't loose your data, but you'll have to repeat the same (manual) operation everywhere your app is deployed... If it's only installed on your local workstation that might be ok, else it's not a reliable professional production-level option.
  3. Use South (which seems to be installed since you do have a migrate command available.

Note that solution #3 imply that you do create the migration files for your app, as documented here : http://south.readthedocs.org/en/latest/tutorial/part1.html#the-first-migration

bruno desthuilliers
  • 75,974
  • 6
  • 88
  • 118
0

It just happened that I faced the same issue with django 1.9.x, where I added a new field in my django app which triggered the same error as you mentioned above. I logged into the dbshell environment using

python manage.p dbshell # I know some use ./manage.py

and dropped all of my tables by running the following command within the dbshell to drop the tables

your_psql=# drop schema public cascade;

This will drop all of your tables (be careful as you may lose your data, there away to keep the data!) and you will get a message right after executing this command tells you that all dropped. Right after that run the following command to create the schema again, otherwise your server will not run:

your_psql=# create schema public;

Then just do the

python manage.py makemigrations # you might not need this, and 
python manage.py migrate

And you're ready to go.

I know this answer might be very late but I hope it will help someone.

Cheers

Berkelian
  • 21
  • 1
  • 3