2๐
The models.py needs to be inside the application package, rather than in the main directory for the makemigrations to work.
39๐
Iโve met this problem during development and this combination helps me:
python manage.py makemigrations mymodule
This command create migrations for the specific module. It should be in INSTALLED_APPS
, but youโll get warning if itโs not in there.
python manage.py migrate
Also, mention answer by xiaohen, Iโve create packages with PyCharm, so Iโve got init.py file by default.
- [Django]-How to completely uninstall a Django app?
- [Django]-Update model django through kwargs
- [Django]-Django how to pass custom variables to context to use in custom admin template?
17๐
I encountered similar issue (โNo changes detectedโ when adding new models) when using Django 1.11, and solved by importing the new models (actually better to import all models) in the __init__.py
in models
package:
from .student import Student
from .teacher import Teacher
Itโs written here:
- [Django]-Django-social-auth django-registration and django-profiles โ together
- [Django]-In Django โ Model Inheritance โ Does it allow you to override a parent model's attribute?
- [Django]-Can't run the server on Django (connection refused)
4๐
Ensure your app is registered in the settings.py,
if so then try running:
python manage.py makemigrations "app_name"
- [Django]-How to keep all my django applications in specific folder
- [Django]-Cannot find command 'git' โ windows
- [Django]-Access request in django custom template tags
3๐
You have to run python manage.py makemigrations
first, Second, you have to run python manage.py migrate
to sync db.
If you mkdir
a folder to save your model, you have to add it to __init__.py
.
- [Django]-Best Fabric scripts for Django
- [Django]-Change a Django form field to a hidden field
- [Django]-Django โ No module named _sqlite3
- [Django]-How can I save my secret keys and password securely in my version control system?
- [Django]-Writing test cases for django models
- [Django]-Get all table names in a Django app
1๐
Another issue may be if you have two ForeignKeys that point to the same model without a related_name
to distinguish between them. E.g.
fk1 = models.ForeignKey(OtherModel)
fk2 = models.ForeignKey(OtherModel)
Django should give you a warning: HINT: Add or change a related_name argument to the definition for 'app.Model.fk1' or 'app.Model.fk2'.
But I didnโt see it until I restarted django.
- [Django]-How to get Request.User in Django-Rest-Framework serializer?
- [Django]-What is the default order of a list returned from a Django filter call?
- [Django]-How do you include a csrf token when testing a POST endpoint in django?
1๐
I want to also add apart from the answers provided above if problem still not solved, please do ensure your migrations dir is available in your app folder if not available ensure to create one and make sure to create an
__init__.py
file inside so that python interpreter will be able to identify that the dir is python dir. Please edit if I might have misused some terminologies. Hope this helps.
- [Django]-Pip install the latest version
- [Django]-ImportError: Failed to import test module:
- [Django]-Django โ what goes into the form action parameter when view requires a parameter?
0๐
Also, note that when the abstract
attribute is set to True
in the models Meta
class, the model will be ignored by makemigrations.
Check that the atrribute is set to False
or remove it altogether.
- [Django]-Threaded Django task doesn't automatically handle transactions or db connections?
- [Django]-Make clicked tab active in Bootstrap
- [Django]-Django: ImproperlyConfigured: The SECRET_KEY setting must not be empty
0๐
I would like to add: If the model Meta class has an app_label, and it is different to the INSTALLED_APPS label โ it will fail.
- [Django]-The way to use background-image in css files with Django
- [Django]-Django-reversion and related model
- [Django]-Set Django's FileField to an existing file