python - Why does Django throw a 'does not exist' error when I try to add a field -


currently i'm using default admin portal working fine. inside models.py try add field follows:

class mymodel(models.model):     # new field 'info'     info = models.charfield(max_length=100) 

mymodel has been defined , used in above code wish add single field. rerun sync

python manage.py syncdb creating tables ... installing custom sql ... installing indexes ... installed 0 object(s) 0 fixture(s) 

however django throws error when try use interface

column myproject_mymodel.info not exist 

what doing wrong?

manage.py syncdb create tables not exist, not work adding or removing columns, or modifications columns.

i suggest reading through following chapter of django book (which free online):
chapter 10: advanced models

here steps given in chapter adding fields:

first, take these steps in development environment (i.e., not on production server):

  1. add field model.
  2. run manage.py sqlall [yourapp] see new create table statement model. note column definition new field.
  3. start database’s interactive shell (e.g., psql or mysql, or can use manage.py dbshell). execute alter table statement adds new column.
  4. launch python interactive shell manage.py shell , verify new field added importing model , selecting table (e.g., mymodel.objects.all()[:5]). if updated database correctly, statement should work without errors.

then on production server perform these steps:

  1. start database’s interactive shell.
  2. execute alter table statement used in step 3 of development environment steps.
  3. add field model. if you’re using source-code revision control , checked in change in development environment step 1, time update code (e.g., svn update, subversion) on production server.
  4. restart web server code changes take effect.

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -