Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resolve "ProgrammingError: Column does not exist" after adding model field

Tags:

django

I added a field 'nearbyzips' to my model and now I can't get past these errors. These are the steps I've taken.

manage.py sqlclear accounts

manage.py syncdb

I get no errors from these two commands, but as soon as run manage.py check_permissions, I get:

ProgrammingError:  column accounts.my_profile.nearbyzips" does not exist

I've also installed South (even though I don't want to use it) out of desperation and followed the tutorial for converting an existing project to use South. This did not work either so I remove south from my installed apps and deleted the migrations folder in my accounts folder.

My understanding of 'manage.py sqlclear accounts' is that it will delete the actual database table, and syncdb will then rebuild it. This does not seem to be doing what it should be doing otherwise, it would remove the error I would assume. All I did was add a model field, this should not be this difficult.

Does anyone have any other advice? I've read countless stack overflow posts on this subject and the only real solution I'm reading is to use sqlclear which I have done, so I'm worried that I've hit a dead end as far as fixing this issue.

like image 722
stephan Avatar asked Feb 15 '15 22:02

stephan


2 Answers

manage.py sqlclear just prints the SQL DROP operators but not executes them. To real drop of the app's tables you need to execute these DROPs:

python manage.py sqlclear accounts | python manage.py dbshell

To add the column without dropping the tables you can execute sql command and then copy the field definition to the ALTER TABLE operator:

echo "ALTER TABLE accounts_my_profile ADD COLUMN nearbyzips CHAR(100);" | python manage.py dbshell
like image 190
catavaran Avatar answered Oct 11 '22 13:10

catavaran


I solved it,If anyone has the same problem:

  1. you have to completely reset your heroku database with heroku pg:reset DATABASE_URL

  2. do heroku run python manage.py syncdb

  3. do heroku run python manage.py migrate

like image 24
Daniel Avatar answered Oct 11 '22 13:10

Daniel