Python Forum

Full Version: django migrate/migrations
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm following a Django course on Udemy.com and there is what my django app's (msg) models.py file looked like before I hit the latest problem in the course.


from django.db import models

# Create your models here.

class Message(models.Model):
message = models.CharField(max_length=400)
username = models.CharField(max_length=100)
The video then had me add the following to the file

def __unicode__(self):
return self.message
So now this is what my models.py file looks like.

from django.db import models

# Create your models here.

class Message(models.Model):
message = models.CharField(max_length=400)
username = models.CharField(max_length=100)

[align=left]def __unicode__(self): # is indented[/align]
[align=left]return self.message    # is indented[/align]
I am then told told to run syncdb which didn't work, a quick web search showed that it was an obsolete or deprecated function and that instead I should run makemigrations and then migrate, In both cases it returned No changes detected & No migrations to apply. The video then goes on to run python3 manage.py shell >>> Message.objects.all() which on my system returns <QuerySet [<Message: Message object>, <Message: Message object>, <Message: Message object>]> and as you can see it's not dispalying the messages for each of the objects despite the unicode function because it's not migrating my changes. There is a username and a message string for each of the three message objects. I keep hearing that python is the future of web programming, I'm still struggling with the idea of giving up php for this madness.
Did you add the app into the settings.py?
(Dec-01-2016, 08:25 PM)Mike Ru Wrote: [ -> ]Did you add the app into the settings.py?

Yes.

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'msg',
]
It's the msg app at the very bottom.