programing tip

Django-makemigrations-감지 된 변경 사항 없음

itbloger 2020. 8. 26. 07:38
반응형

Django-makemigrations-감지 된 변경 사항 없음


makemigrations 명령을 사용하여 기존 앱 내에서 마이그레이션을 만들려고했지만 "변경 사항 없음"이 출력됩니다.

일반적으로 startapp명령을 사용하여 새 앱을 만들지 만 만들 때이 앱에 사용하지 않았습니다.

디버깅 후 migrations패키지 / 폴더가 앱에서 누락되어 마이그레이션을 생성하지 않는 것으로 나타났습니다 .

폴더가 없거나 뭔가 빠진 경우 폴더를 생성하면 더 좋을까요?


앱에 대한 초기 마이그레이션을 생성하려면 makemigrations앱 이름을 실행 하고 지정합니다. 마이그레이션 폴더가 생성됩니다.

./manage.py makemigrations <myapp>

앱이 INSTALLED_APPS먼저 (settings.py 내부)에 포함되어야합니다 .


내 문제 (및 솔루션)는 위에서 설명한 것과는 아직 달랐습니다.

나는 models.py파일을 사용하지 않고 models디렉토리를 생성하고 my_model.py거기에 파일을 생성하여 모델을 넣었습니다. Django는 내 모델을 찾을 수 없으므로 적용 할 마이그레이션이 없다고 썼습니다.

내 솔루션은 다음과 같습니다. my_app/models/__init__.py파일에 다음 줄을 추가했습니다.from .my_model import MyModel


django가 makemigrations명령 중에 마이그레이션 할 항목을 감지하지 못하는 이유는 여러 가지가 있습니다 .

  1. 마이그레이션 폴더 앱에 마이그레이션 패키지가 필요합니다.
  2. INSTALLED_APPS .dict에 앱을 지정해야합니다 INSTALLED_APPS.
  3. Verbositymakemigrations -v 3 는 자세한 정보를 위해 실행 하여 시작 합니다. 이것은 문제에 대한 약간의 빛을 비출 수 있습니다.
  4. 전체 경로 에서 INSTALLED_APPS그것은 'apply.apps.MyAppConfig'전체 모듈 응용 프로그램의 설정 경로를 지정하는 것이 좋습니다
  5. - 올바른 설정 파일이 설정되었는지 확인하려는 설정 :manage.py makemigrations --settings mysite.settings
  6. 앱 이름을 명시 적으로 지정합니다. 앱 이름 만 입력하면 앱만 manage.py makemigrations myapp마이그레이션 할 수 있고 문제를 격리하는 데 도움이됩니다.
  7. 모델 메타 체크 당신은 app_label당신의 모델 메타에서 권리 가 있습니다

  8. django 디버그 django 코어 스크립트를 디버그합니다. makemigrations 명령은 매우 간단합니다. pycharm에서 수행하는 방법은 다음과 같습니다 . 이에 따라 스크립트 정의를 변경 (예 : makemigrations --traceback myapp)

여러 데이터베이스 :

  • django db 라우터로 작업 할 때 Db 라우터 는 라우터 클래스 (사용자 지정 라우터 클래스)가 allow_syncdb메서드 를 구현해야합니다 .

makemigrations는 항상 모델 변경에 대한 마이그레이션을 생성하지만 allow_migrate ()가 False를 반환하면


나는이 질문에 대한 많은 답변을 읽었으며 종종 단순히 makemigrations다른 방식으로 실행한다고 언급했습니다 . 하지만 나에게 문제는 Meta모델 하위 클래스에있었습니다.

label = <app name>( apps.py파일, 옆 models.pyviews.py등) 이라는 앱 구성이 있습니다. 혹시 메타 클래스에 앱 레이블과 동일한 레이블이없는 경우 (예 : 너무 큰 앱 하나를 여러 앱으로 분할하기 때문에) 변경 사항이 감지되지 않으며 유용한 오류 메시지도 없습니다. 그래서 내 모델 클래스에서 나는 이제 다음과 같이했습니다.

class ModelClassName(models.Model):

    class Meta:
        app_label = '<app name>' # <-- this label was wrong before.

    field_name = models.FloatField()
    ...

여기서 Django 1.10을 실행합니다.


주석이지만 아마도 대답이어야합니다.

앱 이름이 settings.py에 있는지 확인하십시오. INSTALLED_APPS그렇지 않으면 어떤 작업을 수행하든 마이그레이션이 실행되지 않습니다.

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    'blog',
]

그런 다음 다음을 실행하십시오.

./manage.py makemigrations blog

There are sometimes when ./manage.py makemigrations is superior to ./manage.py makemigrations <myapp> because it can handle certain conflicts between apps.

Those occasions occur silently and it takes several hours of swearing to understand the real meaning of the dreaded No changes detected message.

Therefore, it is a far better choice to make use of the following command:

./manage.py makemigrations <myapp1> <myapp2> ... <myappN>


I had copied a table in from outside of django and the Meta class defaulted to "managed = false". For example:

class Rssemailsubscription(models.Model):
    id = models.CharField(primary_key=True, max_length=36)
    ...
    area = models.FloatField('Area (Sq. KM)', null=True)

    class Meta:
        managed = False
        db_table = 'RSSEmailSubscription'

By changing manged to True, makemigrations started picking up changes.


I had another problem not described here, which drove me nuts.

class MyModel(models.Model):
    name = models.CharField(max_length=64, null=True)  # works
    language_code = models.CharField(max_length=2, default='en')  # works
    is_dumb = models.BooleanField(default=False),  # doesn't work

I had a trailing ',' in one line perhaps from copy&paste. The line with is_dumb doesn't created a model migration with './manage.py makemigrations' but also didn't throw an error. After removing the ',' it worked as expected.

So be careful when you do copy&paste :-)


I solved that problem by doing this:

  1. Erase the "db.sqlite3" file. The issue here is that your current data base will be erased, so you will have to remake it again.
  2. Inside the migrations folder of your edited app, erase the last updated file. Remember that the first created file is: "0001_initial.py". For example: I made a new class and register it by the "makemigrations" and "migrate" procedure, now a new file called "0002_auto_etc.py" was created; erase it.
  3. Go to the "pycache" folder (inside the migrations folder) and erase the file "0002_auto_etc.pyc".
  4. Finally, go to the console and use "python manage.py makemigrations" and "python manage.py migrate".

The solution is you have to include your app in INSTALLED_APPS.

I missed it and I found this same issue.

after specifying my app name migration became successful

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'boards',
]

please note I mentioned boards in last, which is my app name.


A very dumb issue you can have as well is to define two class Meta in your model. In that case, any change to the first one won't be applied when running makemigrations.

class Product(models.Model):
    somefield = models.CharField(max_length=255)
    someotherfield = models.CharField(max_length=255)

    class Meta:
        indexes = [models.Index(fields=["somefield"], name="somefield_idx")]

    def somefunc(self):
        pass

    # Many lines...

    class Meta:
        indexes = [models.Index(fields=["someotherfield"], name="someotherfield_idx")]

I know this is an old question but I fought with this same issue all day and my solution was a simple one.

I had my directory structure something along the lines of...

apps/
   app/
      __init__.py
      app_sub1/
           __init__.py
           models.py
      app_sub2/
           __init__.py
           models.py
      app_sub3/
           __init__.py
           models.py
   app2/
      __init__.py
      app2_sub1/
           __init__.py
           models.py
      app2_sub2/
           __init__.py
           models.py
      app2_sub3/
           __init__.py
           models.py
    main_app/
      __init__.py
      models.py

And since all the other models up until the one I had a problem with were being imported somewhere else that ended up importing from main_app which was registered in the INSTALLED_APPS, I just got lucky that they all worked.

But since I only added each app to INSTALLED_APPS and not the app_sub* when I finally added a new models file that wasn't imported ANYWHERE else, Django totally ignored it.

My fix was adding a models.py file to the base directory of each app like this...

apps/
   app/
      __init__.py
      models.py <<<<<<<<<<--------------------------
      app_sub1/
           __init__.py
           models.py
      app_sub2/
           __init__.py
           models.py
      app_sub3/
           __init__.py
           models.py
   app2/
      __init__.py
      models.py <<<<<<<<<<--------------------------
      app2_sub1/
           __init__.py
           models.py
      app2_sub2/
           __init__.py
           models.py
      app2_sub3/
           __init__.py
           models.py
    main_app/
      __init__.py
      models.py

and then add from apps.app.app_sub1 import * and so on to each of the app level models.py files.

Bleh... this took me SO long to figure out and I couldn't find the solution anywhere... I even went to page 2 of the google results.

Hope this helps someone!


You should add polls.apps.PollsConfig to INSTALLED_APPS in setting.py


INSTALLED_APPS = [

'blog.apps.BlogConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',

]

make sure 'blog.apps.BlogConfig', (this is included in your settings.py in order to make your app migrations)

then run python3 manage.py makemigrations blog or your app name


  1. Make sure your app is mentioned in installed_apps in settings.py
  2. Make sure you model class extends models.Model

First of all, make sure your app is registered in the Installed_app in the setting.py Then the above answer works perfectly fine


I forgot to put correct arguments:

class LineInOffice(models.Model):   # here
    addressOfOffice = models.CharField("Корхоная жош",max_length= 200)   #and here
    ...

in models.py and then it started to drop that annoying

No changes detected in app 'myApp '

참고URL : https://stackoverflow.com/questions/36153748/django-makemigrations-no-changes-detected

반응형