I've read a lot of questions with answers including here and here but without an answer working. Here are my 2 models that are problematic:
# coding=UTF-8
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
from django.utils.translation import ugettext_lazy as _
from app.models.generic import BaseModel
from app.models.personne import Personne
@python_2_unicode_compatible
class Message(BaseModel):
src = models.ForeignKey('Personne', related_name='message_src')
dst = models.ForeignKey('Personne', related_name='message_dst')
is_read = models.BooleanField(default=False)
message = models.TextField(null=True, blank=True,
verbose_name=_(u'Messages'))
def __str__(self):
return u'{} : {} <> {} ({}) : "{}"'.format(
self.date_creation.strftime('%Y-%m-%d %H:%M:%S'),
self.src.full_name(), self.dst.full_name(),
_(u'read') if self.is_read else _(u'unread'),
self.message_summary()
).strip()
class Meta:
ordering = ["date_creation"]
@python_2_unicode_compatible
class Conversation(BaseModel):
personnes = models.ManyToManyField(Personne, related_name='conversations')
messages = models.ManyToManyField(Message, related_name='conversations')
order_with_respect_to = 'messages'
def __str__(self):
return _(u'Conversation n.{}').format(self.pk).strip()
Each time I do a migrate
I keep getting this question, and I always answer yes
:
The following content types are stale and need to be deleted:
app | conversation_personnes
app | conversation_messages
Any objects related to these content types by a foreign key will also
be deleted. Are you sure you want to delete these content types?
If you're unsure, answer 'no'.
Type 'yes' to continue, or 'no' to cancel: yes
Process finished with exit code 0
This is not a possible duplicate of this question.
Here's the snapshot of my django_content_type
table, there are no model like conversation_personnes
or conversation_messages
:
Thus if I try:
>>> from django.contrib.contenttypes.models import ContentType
ct = ContentType.objects.get(app_label='app', model='conversation_personnes')
ct.delete()
Traceback (most recent call last):
File "<input>", line 2, in <module>
File "C:\Python27\lib\site-packages\django\db\models\manager.py", line 127, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "C:\Python27\lib\site-packages\django\db\models\query.py", line 334, in get
self.model._meta.object_name
DoesNotExist: ContentType matching query does not exist.
The only places in my whole code where I find conversation_personnes
is a migration file that contains:
File 0060_messagethrough.py
class Migration(migrations.Migration):
dependencies = [
('app', '0059_auto_20160226_1752'),
]
operations = [
migrations.CreateModel(
name='MessageThrough',
fields=[
],
options={
'proxy': True,
},
bases=('app.conversation_messages',),
),
]
...and
File 0058_auto_20160225_0106.py
class Migration(migrations.Migration):
dependencies = [
('app', '0057_conversation_personnes'),
]
operations = [
migrations.RemoveField(
model_name='message',
name='conversation',
),
migrations.AddField(
model_name='conversation',
name='messages',
field=models.ManyToManyField(to='app.Message'),
),
]
What am I missing?