【问题标题】:How can I create database in the project folder in Django?如何在 Django 的项目文件夹中创建数据库?
【发布时间】:2019-05-24 16:49:06
【问题描述】:

我在 Django 中有一个非常简单的网站,我不想为此单独创建一个应用程序。因此,在创建 django 项目时不会出现模型和 admin.py 文件。当我们创建一个应用程序时,这些文件会自动创建,我们必须在 Setting.py 中注册。

但我的项目很短,我不想为此创建额外的应用程序。有没有办法在项目文件夹本身中创建这些数据库模型?

我尝试了什么:

1. created a models.py file : wrote my database model in it
2. also created an admin.py file and registered the database model
3. In the setting.py file added the project folder itself

但这似乎不起作用,因为当我尝试创建迁移时,它显示我没有检测到任何更改。

【问题讨论】:

  • 我知道你的项目很简单,但是创建一个应用程序(子文件夹)有什么问题?
  • 没问题,我只是问有没有可能
  • 我认为如果你现在遵循默认结构(没有变通方法),如果你的项目变得更大,将来会更容易和安全。

标签: python django database django-models


【解决方案1】:

Django 项目!= Django 应用程序。您必须以 django 方式进行操作,创建 Django 项目,然后创建您在 django 项目中注册的 django 应用程序。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-09-22
    • 2012-07-14
    • 2019-03-17
    • 2020-08-25
    • 2021-06-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多