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

I have added the "nearbyzips" field to my model, and now I can not get past these errors. These are the steps that I have taken.

manage.py sqlclear accounts manage.py syncdb 

I do not get 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 also set the South (although I don't want to use it) out of desperation and followed the tutorial to convert an existing project to use the South. This did not work, so I remove the south from the installed applications and delete the migration 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 restore it. It seems that this does not do what should be done differently, it will eliminate the error that I would suggest. All I did was add a model field, it should not be so difficult.

Does anyone have any other advice? I read countless entries on this subject, and the only real solution I read is to use sqlclear, which I made, so I worry that I hit a dead end to fix this problem.

+6
source share
2 answers

manage.py sqlclear simply prints the SQL DROP statements, but does not execute them. To actually reduce application tables, you need to do the following DROPs:

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

To add a column without dropping the table, you can execute the sql command and then copy the field definition to the ALTER TABLE statement:

 echo "ALTER TABLE accounts_my_profile ADD COLUMN nearbyzips CHAR(100);" | python manage.py dbshell 
+5
source

I solved this if someone has the same problem:

  • you must completely reset create your heroku database using heroku pg:reset DATABASE_URL

  • do heroku run python manage.py syncdb

  • do heroku run python manage.py migrate

+1
source

Source: https://habr.com/ru/post/982531/


All Articles