Django - makemigrations - No changes detected

前端 未结 30 1317
伪装坚强ぢ
伪装坚强ぢ 2020-12-02 04:44

I was trying to create migrations within an existing app using the makemigrations command but it outputs \"No changes detected\".

Usually I create new apps using the

相关标签:
30条回答
  • 2020-12-02 05:24

    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 '

    0 讨论(0)
  • 2020-12-02 05:24

    If you have the managed = True in yout model Meta, you need to remove it and do a migration. Then run the migrations again, it will detect the new updates.

    0 讨论(0)
  • 2020-12-02 05:26

    I've read many answers to this question often stating to simply run makemigrations in some other ways. But to me, the problem was in the Meta subclass of models.

    I have an app config that says label = <app name> (in the apps.py file, beside models.py, views.py etc). If by any chance your meta class doesn't have the same label as the app label (for instance because you are splitting one too big app into multiple ones), no changes are detected (and no helpful error message whatsoever). So in my model class I have now:

    class ModelClassName(models.Model):
    
        class Meta:
            app_label = '<app name>' # <-- this label was wrong before.
    
        field_name = models.FloatField()
        ...
    

    Running Django 1.10 here.

    0 讨论(0)
  • 2020-12-02 05:26

    I had a similar issue with django 3.0, according migrations section in the official documentation, running this was enough to update my table structure:

    python manage.py makemigrations
    python manage.py migrate
    

    But the output was always the same: 'no change detected' about my models after I executed 'makemigrations' script. I had a syntax error on models.py at the model I wanted to update on db:

    field_model : models.CharField(max_length=255, ...)
    

    instead of:

    field_model = models.CharField(max_length=255, ...)
    

    Solving this stupid mistake, with those command the migration was done without problems. Maybe this helps someone.

    0 讨论(0)
  • 2020-12-02 05:27

    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

    0 讨论(0)
  • 2020-12-02 05:27

    This might hopefully help someone else, as I ended up spending hours trying to chase this down.

    If you have a function within your model by the same name, this will remove the value. Pretty obvious in hindsight, but nonetheless.

    So, if you have something like this:

    class Foobar(models.Model):
        [...]
        something = models.BooleanField(default=False)
    
        [...]
        def something(self):
            return [some logic]
    

    In that case, the function will override the setting above, making it "invisible" to makemigrations.

    0 讨论(0)
提交回复
热议问题