简体   繁体   English

更改目录结构后,Django迁移未检测到更改

[英]Django migrations no changes detected after changing directory structure

I have created a Django project using this directory structure : 我使用以下目录结构创建了一个Django项目:

bi3online
    __init__.py
    migrations
        __init__.py
    static
    templates
    media
    manage.py
    models.py
    urls.py
    views.py
    wsgi.py
    ...

When I run python manage.py makemigrations and python manage.py migrate it only creates migrations for auth app and then when I try again it says no changes detected. 当我运行python manage.py makemigrationspython manage.py migrate migration时,它只会为auth应用程序创建迁移,然后当我再次尝试时,它说未检测到更改。 It seems that migrations work only with apps but I'm not sure. 似乎迁移仅适用于应用程序,但我不确定。

models.py models.py

from django.db import models


class Book(models.Model):
    id = models.AutoField(primary_key=True)
    title = models.CharField(null=False, blank=False, max_length=64)

Just to sum up the comments and lead you to the solution: 只是为了总结评论并引导您找到解决方案:

Django works with apps. Django适用于应用程序。 The app is a folder with models.py , apps.py and views.py modules (optionally other). 该应用程序是一个文件夹,其中包含models.pyapps.pyviews.py模块(可选为其他)。

Say your app is called books . 假设您的应用称为books For Django to recognize the folder as an app you need to add your app to settings.py : 为了让Django将该文件夹识别为应用程序,您需要将应用程序添加到settings.py

INSTALLED_APPS = [
    ... ,
    'books'
]

And you need your apps.py module in books folder to have this: 您需要在books文件夹中的apps.py模块具有以下功能:

from django.apps import AppConfig


class BooksConfig(AppConfig):
     name = 'books'

And you should have the following project structure: 并且您应该具有以下项目结构:

bi3online
    books
        migrations
            __init__.py
        __init__.py
        models.py
        views.py
    bi3online
        __init__.py
        manage.py
        urls.py
        wsgi.py
    static
    templates
    media

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM