【问题标题】:How to link existing tables in database to Django Models?如何将数据库中的现有表链接到 Django 模型?
【发布时间】:2017-09-18 06:18:11
【问题描述】:

我正在学习 Django,我需要知道我是否可以将数据库中已经存在的表链接到模型(因为我听说表是由 Django 为我们在 django app 中创建的任何模型创建的)。

如果可以,怎么办?

【问题讨论】:

    标签: django django-models django-database django-database-functions


    【解决方案1】:

    inspectdb 现在可以正常工作了。 (Django 1.7+)只需运行 manage.py inspectdb 将为数据库中的所有表创建类并显示在控制台上。

     $ python manage.py inspectdb
    

    使用标准 Unix 输出重定向将其保存为文件:

     $ python manage.py inspectdb > models.py
    

    Read further from here.

    【讨论】:

      猜你喜欢
      • 2017-07-31
      • 1970-01-01
      • 1970-01-01
      • 2014-12-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-15
      相关资源
      最近更新 更多