[英]python manage.py makemigrations : No changes detected
I am working on a project using django and I am using pycharm software.我正在使用 django 开发一个项目,并且正在使用 pycharm 软件。 In my 'store' directory i have a python package called 'models' in which there are two python files :- init .py and
product.py
.在我的“商店”目录中,我有一个名为“模型”的 python 包,其中有两个 python 文件:- init .py 和
product.py
。 The problem i am getting is that I cannot create table using the command even when I am importing the 'Product' class from product module in init .py file.我遇到的问题是,即使我从init .py 文件中的产品模块导入“产品”类,我也无法使用该命令创建表。 Even both the modules are also in the same package.
甚至两个模块也在同一个包中。 Here is the code of the product.py file:-
这是 product.py 文件的代码:-
from django.db import models
class Product(models.Model):
name = models.CharField(max_length=50)
price = models.IntegerField(default=0)
description = models.CharField(max_length=200, default='')
image = models.ImageField(upload_to='products/')
And here is the code of init .py file:-这是init .py 文件的代码:-
from .product import Product
But when i am running the command on terminal i am getting this error:-但是当我在终端上运行命令时,我收到了这个错误:-
(venv) C:\Users\Admin\PycharmProjects\SMart>python manage.py makemigrations
No changes detected
您必须将应用程序的名称 < store
> 放入设置中的 INSTALLED_APPS 列表中。
I had the same issue with Django 4. To solve it, I created migrations/__init__.py
file in every app directory.我在使用 Django 4 时遇到了同样的问题。为了解决这个问题,我在每个应用程序目录中创建了
migrations/__init__.py
文件。 So just run these command for every app:因此,只需为每个应用程序运行这些命令:
mkdir appname/migrations
touch appname/migrations/__init__.py
Then use manage.py
:然后使用
manage.py
:
python3 manage.py makemigrations
python3 manage.py migrate
And it worked.它奏效了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.