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):
- add field model.
- run
manage.py sqlall [yourapp]
see newcreate table
statement model. note column definition new field.- start database’s interactive shell (e.g.,
psql
ormysql
, or can usemanage.py dbshell
). executealter table
statement adds new column.- 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:
- start database’s interactive shell.
- execute
alter table
statement used in step 3 of development environment steps.- 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.- restart web server code changes take effect.
Comments
Post a Comment