Django - makemigrations - No changes detected

前端 未结 30 1320
伪装坚强ぢ
伪装坚强ぢ 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:32

    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".
    0 讨论(0)
  • 2020-12-02 05:32

    One more edge case and solution:

    I added a boolean field, and at the same time added an @property referencing it, with the same name (doh). Commented the property and migration sees and adds the new field. Renamed the property and all is good.

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

    My problem with this error, was that I had included:

    class Meta:
       abstract = True
    

    Inside model that I wanted to creation migrate for.

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

    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.

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

    The Best Thing You can do is, Delete the existing database. In my case, I were using phpMyAdmin SQL database, so I manually delete the created database overthere.

    After Deleting: I create database in PhpMyAdmin, and doesn,t add any tables.

    Again run the following Commands:

    python manage.py makemigrations

    python manage.py migrate

    After These Commands: You can see django has automatically created other necessary tables in Database(Approx there are 10 tables).

    python manage.py makemigrations <app_name>

    python manage.py migrate

    And Lastly: After above commands all the model(table) you have created are directly imported to the database.

    Hope this will help.

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

    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>

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