Home  >  Article  >  Backend Development  >  python django | models

python django | models

巴扎黑
巴扎黑Original
2016-12-09 10:37:491367browse

Learn from Daniel’s website:

After the models class is modified, the database should also be updated. However, the syncdb command only creates tables in the database and does not modify or delete the data model synchronously. At this time, you need to manually make corresponding modifications in the database or run syncdb to recreate the table before deleting it.
Manual modification process:
1. sudo python manage.py sqlall depotapp View all fields of the table
2. sudo python manage.py dbshell Use the dbshell provided by django to add fields
sqlite> begin;
sqlite> alter table depotapp_product add column date_available data not null default 0;
sqlite> commit;
{ctrl+d when exiting}{delete field-->drop column;delete model-->drop table;delete many-to-many association-->drop table( Automatically generated association table)}
3. python manage.py shell to verify the database
In [1]: from depotapp.models import Product

In [2]: Product.objects.all()
If no error is reported, it is ok

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Python reads excel xlrdNext article:Python reads excel xlrd