Is it possible to generate django models from the database?

前端 未结 3 1573
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-28 03:51

I\'ve been messing around with Django and the Django ORM at home, and I\'ve got to say, I feel it is one of the best out there in terms of ease of use.

However, I wa

3条回答
  •  迷失自我
    2020-11-28 04:19

    Yes, use the inspectdb command:

    • http://docs.djangoproject.com/en/dev/ref/django-admin/#inspectdb

    inspectdb

    Introspects the database tables in the database pointed-to by the DATABASE_NAME setting and outputs a Django model module (a models.py file) to standard output.

    Use this if you have a legacy database with which you'd like to use Django. The script will inspect the database and create a model for each table within it.

    As you might expect, the created models will have an attribute for every field in the table. Note that inspectdb has a few special cases in its field-name output:

    [...]

提交回复
热议问题