Django 1.11. I recently added the following module to myapp.models:
from django.db import models
from ordered_model.models import OrderedModel
from .songs import Song
class Service(models.Model):
name = models.CharField(max_len=200, unique=True)
date = models.DateField(blank=True)
items = models.ManyToManyField(ServiceItem)
class Meta:
ordering = ('-date', 'name')
class ServiceItem(OrderedModel):
item = models.ForeignKey(Song)
song_custom_order = models.CharField(max_len=50, blank=True)
order_with_respect_to = 'service'
class Meta(OrderedModel.Meta):
pass
I have other models in another module (in the same directory). When I run ./manage.py makemigrations, the script finds my changes in my other module, but not in this one. FWIW, this module is all new code with no previous migration history.
Any ideas why these changes aren't getting picked up?
The models must be imported in the __init__.py file of the models package. From the docs:
The manage.py startapp command creates an application structure that includes a models.py file. If you have many models, organizing them in separate files may be useful.
To do so, create a models package. Remove models.py and create a myapp/models/ directory with an __init__.py file and the files to store your models. You must import the models in the __init__.py file. For example, if you had organic.py and synthetic.py in the models directory:
myapp/models/__init__.py
from .organic import Person
from .synthetic import Robot
Try , running makemigrations specifying the app_name,
python manage.py makemigrations <your_app_name>
or
./manage.py makemigrations <your_app_name>
This should do the trick.
Also, make sure your_app_name is included in the INSTALLED_APPS setting in settings.py file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With