Django 4.2.1 with django-cookiecutter 2023.05.09: makemigrations doesn't create migration file for new model

huangapple go评论47阅读模式
英文:

Django 4.2.1 with django-cookiecutter 2023.05.09: makemigrations doesn't create migration file for new model

问题

以下是您要翻译的内容:

"I'm using Django 4.2.1 with the latest version of django-cookiecutter (2023.05.09) on MacOS Ventura 13.3.1, and I'm having trouble getting the makemigrations command to create a migration file for a new model I've added to my Django project.

Here's what I've done thus far:

I added the new model to my models.py file in my app directory:

from django.db import models

class TestModel(models.Model):
    name = models.CharField(max_length=50)

I created an empty migration file for the app with the makemigrations command:

python manage.py makemigrations myapp --empty

I ran the makemigrations command again to create a migration for the new model, but it didn't create a new migration file:

python manage.py makemigrations

I've double-checked that the TestModel app is included in my INSTALLED_APPS list in my settings.py file, and I've checked that there are no syntax errors in my models.py file.

I've also tried running the check command to see if there are any issues with my code, but it doesn't show any problems:

python manage.py check

I've also tried running the makemigrations command with the --verbosity 3 option to get more detailed output, but it doesn't show any errors or warnings related to the TestModel app.

I've also checked that the migration file has the correct name and is located in the correct directory. The migration file is named 0001_initial.py and is located in the myapp/migrations/ directory.

This is what my directory tree looks like:

[Directory tree]

What could be causing makemigrations to not create a migration file for my new model? Are there any additional steps I can take to diagnose the problem? Any help would be appreciated!"

英文:

I'm using Django 4.2.1 with the latest version of django-cookiecutter (2023.05.09) on MacOS Ventura 13.3.1, and I'm having trouble getting the makemigrations command to create a migration file for a new model I've added to my Django project.

Here's what I've done thus far:

I added the new model to my models.py file in my app directory:

from django.db import models

class TestModel(models.Model):
    name = models.CharField(max_length=50)

I created an empty migration file for the app with the makemigrations command:

python manage.py makemigrations myapp --empty

I ran the makemigrations command again to create a migration for the new model, but it didn't create a new migration file:

python manage.py makemigrations

I've double-checked that the TestModel app is included in my INSTALLED_APPS list in my settings.py file, and I've checked that there are no syntax errors in my models.py file.

I've also tried running the check command to see if there are any issues with my code, but it doesn't show any problems:

python manage.py check

I've also tried running the makemigrations command with the --verbosity 3 option to get more detailed output, but it doesn't show any errors or warnings related to the TestModel app.

I've also checked that the migration file has the correct name and is located in the correct directory. The migration file is named 0001_initial.py and is located in the myapp/migrations/ directory.

This is what my directory tree looks like:

└─ base
   ├─ .dockerignore
   ├─ .editorconfig
   ├─ .envs
   │  ├─ .local
   │  │  ├─ .django
   │  │  └─ .postgres
   │  └─ .production
   │     ├─ .django
   │     └─ .postgres
   ├─ .pre-commit-config.yaml
   ├─ .readthedocs.yml
   ├─ CONTRIBUTORS.txt
   ├─ LICENSE
   ├─ MailHog
   ├─ README.md
   ├─ SECURITY.md
   ├─ base
   │  ├─ __init__.py
   │  ├─ conftest.py
   │  ├─ contrib
   │  │  ├─ __init__.py
   │  │  └─ sites
   │  │     ├─ __init__.py
   │  │     └─ migrations
   │  │        ├─ 0001_initial.py
   │  │        ├─ 0002_alter_domain_unique.py
   │  │        ├─ 0003_set_site_domain_and_name.py
   │  │        ├─ 0004_alter_options_ordering_domain.py
   │  │        ├─ __init__.py
   │  ├─ media
   │  ├─ static
   │  │  ├─ css
   │  │  ├─ fonts
   │  │  ├─ images
   │  │  ├─ js
   │  │  ├─ sass
   │  │  └─ webpack_bundles
   │  ├─ templates
   │  │  ├─ 403.html
   │  │  ├─ 404.html
   │  │  ├─ 500.html
   │  │  ├─ account
   │  │  │  ├─ account_inactive.html
   │  │  │  ├─ base.html
   │  │  │  ├─ email.html
   │  │  │  ├─ email_confirm.html
   │  │  │  ├─ login.html
   │  │  │  ├─ logout.html
   │  │  │  ├─ password_change.html
   │  │  │  ├─ password_reset.html
   │  │  │  ├─ password_reset_done.html
   │  │  │  ├─ password_reset_from_key.html
   │  │  │  ├─ password_reset_from_key_done.html
   │  │  │  ├─ password_set.html
   │  │  │  ├─ signup.html
   │  │  │  ├─ signup_closed.html
   │  │  │  ├─ verification_sent.html
   │  │  │  └─ verified_email_required.html
   │  │  ├─ base.html
   │  │  ├─ pages
   │  │  │  ├─ about.html
   │  │  │  └─ home.html
   │  │  └─ users
   │  │     ├─ user_detail.html
   │  │     └─ user_form.html
   │  ├─ users
   │  │  ├─ __init__.py
   │  │  ├─ adapters.py
   │  │  ├─ admin.py
   │  │  ├─ api
   │  │  ├─ apps.py
   │  │  ├─ context_processors.py
   │  │  ├─ forms.py
   │  │  ├─ managers.py
   │  │  ├─ migrations
   │  │  │  ├─ 0001_initial.py
   │  │  │  ├─ __init__.py
   │  │  ├─ models.py
   │  │  ├─ tasks.py
   │  │  ├─ urls.py
   │  │  └─ views.py
   │  ├─ utils
   │  │  ├─ __init__.py
   │  │  └─ storages.py
   │  └─ website
   │     ├─ __init__.py
   │     ├─ __pycache__
   │     ├─ admin.py
   │     ├─ apps.py
   │     ├─ migrations
   │     │  ├─ 0001_initial.py
   │     │  ├─ __init__.py
   │     ├─ models
   │     │  ├─ __init__.py
   │     ├─ models.py
   │     ├─ tests.py
   │     ├─ urls.py
   │     └─ views.py
   ├─ config
   │  ├─ __init__.py
   │  ├─ api_router.py
   │  ├─ asgi.py
   │  ├─ celery_app.py
   │  ├─ settings
   │  │  ├─ __init__.py
   │  │  ├─ base.py
   │  │  ├─ local.py
   │  │  ├─ production.py
   │  │  └─ test.py
   │  ├─ urls.py
   │  ├─ websocket.py
   │  └─ wsgi.py
   ├─ docs
   ├─ dump.rdb
   ├─ local.yml
   ├─ locale
   │  └─ README.rst
   ├─ manage.py
   ├─ merge_production_dotenvs_in_dotenv.py
   ├─ package-lock.json
   ├─ package.json
   ├─ production.yml
   ├─ pyproject.toml
   ├─ requirements
   ├─ setup.cfg
   ├─ staticfiles
   ├─ tests
   ├─ webpack
   └─ webpack-stats.json

What could be causing makemigrations to not create a migration file for my new model? Are there any additional steps I can take to diagnose the problem? Any help would be appreciated!

答案1

得分: 0

我没有尝试过,但有一个模型文件夹和模型文件...也许这导致找不到model.py:

   │     ├─ models
   │     │  ├─ __init__.py
   │     ├─ models.py

根据你的问题,不清楚你在哪个应用/模型下遇到了问题。

在那个特定应用的初始迁移文件中有什么内容?

英文:

I did not try it but there is a model folder and model file ... maybe that causes model.py to not be found:

   │     ├─ models
   │     │  ├─ __init__.py
   │     ├─ models.py

from you question it is not clear which app/models you are having a problem with.

What is in the inital migration file of that specific app?

答案2

得分: 0

要创建一个新的Django应用程序,我建议使用python manage.py startapp <app_name>命令,而不是django_admin startapp <app_name>python manage.py命令是一个方便的包装器,提供额外的功能并与Django项目更好地集成。

startapp命令用于在项目中创建一个新的Django应用程序。通过运行python manage.py startapp <app_name>,Django将为您的应用程序生成必要的文件和目录。这包括应用程序的模型、视图、模板和其他组件。

英文:

To create a new Django app, I recommend using the python manage.py startapp &lt;app_name&gt; command instead of django_admin startapp &lt;app_name&gt;. The python manage.py command is a convenience wrapper that provides additional functionality and integrates better with Django projects.

The startapp command is used to create a new Django app within your project. By running python manage.py startapp &lt;app_name&gt;, Django will generate the necessary files and directories for your app. This includes the app's models, views, templates, and other components.

huangapple
  • 本文由 发表于 2023年5月13日 11:20:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/76240927.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定