Reverse-Generate Django models from a database

Source: Internet
Author: User

Is there a way to implement the models of the Django database backwards? The answer is yes.

1. Configuring the Database configuration section in settings.py

DATABASES = {    'default': {        'ENGINE':'Django.db.backends.mysql',         'NAME':'MyDB',                             'USER':'Root',                        'PASSWORD':'Password',         'HOST':'127.0.0.1',        'PORT':'3306',     }}

2. Run the command

Python mysite/manage.py inspectdb > mysite/myapp/models.py or: Python mysite/manage.py inspectdb

3. Generate additional tables as needed. Perform sync

Python manage.py syncdb

This is done by generating the Django system tables into the data you already have so that Django can use it, such as a session that relies on Django's own database.

Reverse-Generate Django models from a database

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.