简体   繁体   English

python manage.py makemigrations:未检测到更改

[英]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.

相关问题 python manage.py makemigrations给出没有检测到变化? - python manage.py makemigrations gives No changes detected? python manage.py makemigrations博客未在应用“博客”中返回未检测到的更改 - python manage.py makemigrations blog returns no changes detected in app 'blog' 我执行Python manage.py makemigrations和迁移时未检测到更改 - No changes detected when i excute Python manage.py makemigrations and migrate 无法从源/py manage.py makemigrations 解析导入“django.db.models”未检测到更改 - Import "django.db.models" could not be resolved from source / py manage.py makemigrations No changes detected manage.py (python manage.py makemigrations) 错误 - manage.py (python manage.py makemigrations) Error 无法使用Python的manage.py makemigrations迁移数据库 - Not able to migrate DB, using Python's manage.py makemigrations Django 1.7 python manage.py makemigrations轮询SyntaxError - Django 1.7 python manage.py makemigrations polls SyntaxError 终端卡在 python manage.py makemigrations 和 runserver - Terminal is stuck on python manage.py makemigrations and runserver python manage.py makemigrations在升级Django时给出错误 - python manage.py makemigrations giving error on upgrading django python manage.py makemigrations没有名为错误的模块 - python manage.py makemigrations no module named error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM