python django | models

巴扎黑
Release: 2016-12-09 10:37:49
Original
1335 people have browsed it

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!